-1

Using python code to get descriptions of books from Goodreads, however my code doesn't allow me to sign in before starting the actual search, I need to obviously add code to do the signin with my username and pw THEN execute the search.

def fetch_description_genre_and_date_from_goodreads(self, book_author, book_title):
    """Fetch book description from Goodreads."""
    self.driver.get('http://goodreads.com/search?query=' + urllib.parse.quote_plus('{} {}'.format(book_author, book_title)))
    genre = None
    publish_date = None
    try:
        self.driver.find_elements_by_class_name('bookTitle')[0].click()
        try:
            WebDriverWait(self.driver, 5).until(
                EC.presence_of_element_located((By.CLASS_NAME, 'bookPageGenreLink')))
            genre = self.driver.find_element_by_class_name('bookPageGenreLink').text
        except TimeoutException:
            pass
        try:
            WebDriverWait(self.driver, 5).until(
                EC.presence_of_element_located((By.XPATH, "//div[@id='details']/div[2]")))
            publish_date = self.driver.find_element_by_xpath("//div[@id='details']/div[2]").text.split('by')[0].rstrip()
            if not 'published' in publish_date.lower():
                publish_date = None
        except TimeoutException:
            pass
        long_description = False
        WebDriverWait(self.driver, 5).until(
            EC.presence_of_element_located((By.ID, 'description')))
        for anchor_tag in self.driver.find_element_by_id('description').find_elements_by_tag_name('a'):
            if anchor_tag.text == '...more':
                anchor_tag.click()
                long_description = True
                break
        return (self.driver.find_elements_by_xpath("//span[starts-with(@id,'freeText')]")[1].text, genre, publish_date)\
            if long_description else (self.driver.find_elements_by_xpath("//span[starts-with(@id,'freeText')]")[0].text, genre, publish_date)
    except (IndexError, TimeoutException):
        return None, genre, publish_date

What happens now is I get the popup for sign in first and the error:

Message: unknown error: Element <a class="bookTitle" itemprop="url" 
href="/book/show/41880080-all-that-you-leave-behind?from_search=true">...</a> is 
not clickable at point (214, 326). Other element would receive the click: <div class="loginModal__popUpBook" data-reactid=".2z3blpsmww.0.1.2"></div>

Please can someone perhaps assist me?

TheGene
  • 1
  • 3
  • The button is probably hidden, try this solution [here](https://stackoverflow.com/a/37880313/7805146) – Luiz Fernando Lobo Aug 22 '19 at 17:24
  • I looked at that, added as follows to my code `self.driver.get('http://goodreads.com/search?query=' + urllib.parse.quote_plus('{} {}'.format(book_author, book_title))) element = self.driver.find_element_by_class_name('modal_close') self.driver.execute_script("arguments[0].click();", element)` it now says it cannot locate the element. need help with that? – TheGene Aug 23 '19 at 05:31
  • My problem is addressing the element find correctly ... the element"modal_close" that needs be clicked is inside `
    ` if I understand correctly?
    – TheGene Aug 23 '19 at 05:53

1 Answers1

0

I have a solution, if this helps anyone else. Instead of trying to click in the modal popup, I moved the cursor and clicked on the page itself, and that removes the popup window. Then the code proceeds correctly. I added this: self.driver.execute_script('el = document.elementFromPoint(0, 30); el.click();') After: self.driver.get('http://goodreads.com/search?query=' + urllib.parse.quote_plus('{} {}'.format(book_author, book_title)))

and that works 100%. Thank you for trying to help.

TheGene
  • 1
  • 3