Skip to content

Commit 67f10a1

Browse files
authored
Account for ArtRemix/PoemPostcard xpath changes (#32)
account for ArtRemix/PoemPostcard xpath changes
1 parent 726aad9 commit 67f10a1

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

artscraper/googleart.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,29 @@ def _get_metadata(self):
159159
def get_image(self):
160160
"""Get a binary PNG image in memory."""
161161
self.wait(self.min_wait)
162-
elem = self.driver.find_element(
163-
"xpath", "/html/body/div[3]/div[3]/div/div/div[2]/div[3]")
162+
163+
def _find_clickable_element_to_enlarge_image():
164+
try:
165+
# Without ArtRemix/PoemPostcard
166+
elem = self.driver.find_element(
167+
"xpath", "/html/body/div[3]/div[3]/div/div/div[2]/div[3]")
168+
except NoSuchElementException:
169+
# With ArtRemix/PoemPostcard
170+
elem = self.driver.find_element(
171+
"xpath", "/html/body/div[3]/div[3]/div/div/div[3]/div[3]/div[1]")
172+
173+
return elem
174+
175+
# Find element to click on to enlarge image
176+
elem = _find_clickable_element_to_enlarge_image()
164177

165178
webdriver.ActionChains(
166179
self.driver).move_to_element(elem).click(elem).perform()
167180

168181
self.wait(self.min_wait * 2, update=False)
169-
elem = self.driver.find_element(
170-
"xpath", "/html/body/div[3]/div[3]/div/div/div[2]/div[3]")
182+
183+
# Find element to click on to enlarge image, again
184+
elem = _find_clickable_element_to_enlarge_image()
171185

172186
img = elem.screenshot_as_png
173187

@@ -210,9 +224,11 @@ def save_artwork_information(self, link):
210224
Artwork URL.
211225
212226
"""
227+
213228
self.load_link(link)
214229
self.save_metadata()
215230
self.save_image()
216231

232+
217233
def close(self):
218234
self.driver.quit()

0 commit comments

Comments
 (0)