Created
March 1, 2013 00:39
-
-
Save bregenspan/5061480 to your computer and use it in GitHub Desktop.
Quick little script to test an XCode expression against an HTML file, using Scrapy's XPath selector. This is by no means the best or most direct way to test an XPath expression.
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 scrapy.http import TextResponse | |
from scrapy.selector import HtmlXPathSelector | |
XPATH_TO_TEST = "//img/@src" | |
FILE_TO_TEST_AGAINST = "pathtest.html" | |
f = open(FILE_TO_TEST_AGAINST, 'r') | |
test_html = f.read() | |
response = TextResponse('http://www.example.com', status=200, headers=[], body=test_html) | |
hxs = HtmlXPathSelector(response) | |
imgs = hxs.select(XPATH_TO_TEST).extract() | |
print imgs | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment