Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from selenium import webdriver
browser = webdriver.Firefox()
# The list of book titles is in a pandas dataframe
# named 'data', in the column 'title'
for row in range(len(data)):
browser.get("http://www.amazon.com")
time.sleep(1)
elem = browser.find_element_by_name('field-keywords')
if type(data.title[row]) != float:
elem.send_keys(data.title[row])
elem.submit()
try:
time.sleep(1)
book_link = browser.find_element_by_xpath(
"//*[contains(concat(' ', @class, ' '), ' lrg ')]")
book_link.click()
time.sleep(1)
data.found_title[row] = browser.find_element_by_id(
'productTitle').text
data.link[row] = browser.current_url
except NoSuchElementException:
data.found_title[row] = "NotFound"
print "no good"
else:
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.