Skip to content

Instantly share code, notes, and snippets.

@PMeinshausen
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PMeinshausen/c088ab28f515176685cb to your computer and use it in GitHub Desktop.
Save PMeinshausen/c088ab28f515176685cb to your computer and use it in GitHub Desktop.
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