Basic example of using requests and lxml to scrape some data
suggest changer = requests.get("https://httpbin.org")
html_source = r.text
root_element = lxml.html.fromstring(html_source)
Note
root_element.xpath() gives a list of results.
XPath specifies a path to the element we want.
page_title = root_element.xpath('/html/head/title/text()')[0]
print(page_title)
if __name__ == '__main__':
main()
requests and lxml are not imported in these snippets. main is not defined on this page, so that call raises NameError. This sample was not run.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents