Created
May 16, 2012 22:41
-
-
Save justinfay/2714629 to your computer and use it in GitHub Desktop.
A xpath response hook for requests using lxml
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 lxml import etree | |
def xpath(response): | |
response.xpath = etree.HTML(response.content).xpath | |
return response | |
if __name__ == "__main__": | |
import requests | |
r = requests.get('http://example.com', hooks=dict(response=xpath)) | |
r.xpath('//h1/text()') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment