Home > other >  Why Xpath positioning elements, web pages can locate to, code capture?
Why Xpath positioning elements, web pages can locate to, code capture?

Time:10-18


 
The import requests
The from LXML import etree

City_url="http://www.daomubiji.com/"
Headers={the user-agent: "Mozilla/5.0 (Windows NT 10.0; Win64. X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36}
"The response=requests. Get (=city_url url, headers=headers)
HTML=etree. HTML (the response. The text)
Result=HTML. Xpath ('/HTML/body/section/article/a/div/h2/text () ')
Print (result)

# result is empty []

CodePudding user response:

Content is loaded via ajax, direct extraction of course can't extract
  • Related