Last active
August 29, 2015 14:12
-
-
Save dhbradshaw/3108b3ea1a6b81c086b8 to your computer and use it in GitHub Desktop.
Using selenium and Google Chrome's xpaths to find some text
This file contains 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 | |
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