Skip to content

Instantly share code, notes, and snippets.

@dhbradshaw
Last active August 29, 2015 14:12
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 dhbradshaw/3108b3ea1a6b81c086b8 to your computer and use it in GitHub Desktop.
Save dhbradshaw/3108b3ea1a6b81c086b8 to your computer and use it in GitHub Desktop.
Using selenium and Google Chrome's xpaths to find some text
from selenium import webdriver
from lxml import html
#Get the page source as altered by the browser
browser = webdriver.Firefox()
url='http://www.amazon.com/Levi-Magic-Pants-Douglas-Bradshaw-ebook/dp/B0086K9JI0/'
browser.get(url)
html_source = browser.page_source
#Combine it with an xpath that you get from inspecting an element, right-clicking the highlighted code, and then selecting copy xpath
tree = html.fromstring(html_source)
xpath='//*[@id="divsinglecolumnminwidth"]/div[4]/span/span/a'
res=tree.xpath(xpath)
res[0].text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment