Skip to content

Instantly share code, notes, and snippets.

@bregenspan
Created March 1, 2013 00:39
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 bregenspan/5061480 to your computer and use it in GitHub Desktop.
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.
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