Last active
August 29, 2015 14:07
-
-
Save PMeinshausen/c088ab28f515176685cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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