Skip to content

Commit

Permalink
account for ArtRemix/PoemPostcard xpath changes
Browse files Browse the repository at this point in the history
  • Loading branch information
modhurita committed Feb 5, 2024
1 parent fc13ed6 commit 8d734f8
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions artscraper/googleart.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,29 @@ def _get_metadata(self):
def get_image(self):
"""Get a binary PNG image in memory."""
self.wait(self.min_wait)
elem = self.driver.find_element(
"xpath", "/html/body/div[3]/div[3]/div/div/div[2]/div[3]")

def _find_clickable_element_to_enlarge_image():
try:
# Without ArtRemix/PoemPostcard
elem = self.driver.find_element(
"xpath", "/html/body/div[3]/div[3]/div/div/div[2]/div[3]")
except NoSuchElementException:
# With ArtRemix/PoemPostcard
elem = self.driver.find_element(
"xpath", "/html/body/div[3]/div[3]/div/div/div[3]/div[3]/div[1]")

return elem

# Find element to click on to enlarge image
elem = _find_clickable_element_to_enlarge_image()

webdriver.ActionChains(
self.driver).move_to_element(elem).click(elem).perform()

self.wait(self.min_wait * 2, update=False)
elem = self.driver.find_element(
"xpath", "/html/body/div[3]/div[3]/div/div/div[2]/div[3]")

# Find element to click on to enlarge image, again
elem = _find_clickable_element_to_enlarge_image()

img = elem.screenshot_as_png

Expand Down Expand Up @@ -210,9 +224,11 @@ def save_artwork_information(self, link):
Artwork URL.
"""

self.load_link(link)
self.save_metadata()
self.save_image()


def close(self):
self.driver.quit()

0 comments on commit 8d734f8

Please sign in to comment.