An example Analysis of python's strange xpath bug
This article mainly explains the "python strange xpath bug example analysis", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "python strange xpath bug example analysis" bar!
The strange bug encountered while climbing a single page of Lianjia reported the following error: import urllib.request import urllib.parseimport user_agentimport lxml.etree as le import tool import pandas as pdrequest = urllib.request.Request (url=' https://zz.lianjia.com/ditiezufang/li110460711s3320024453090127/rt200600000001/',) Headers= {'User-Agent':user_agent.get_user_agent_pc ()}) response = urllib.request.urlopen (request) data = le.HTML (response.read ()) .XPath (' / / div [@ class= "content__list"] / / div [@ class= "content__list--item"] [1] / / text ()') data1 = le.HTML (response.read ()) .XPath ('/ / div [@ class= "content__list"] / / div [@ class= "content__list--item"] [2] / / text ()') print (data) print (data1) the following does not make an error: import urllib.request import urllib.parseimport user_agentimport lxml.etree as le import tool import pandas as pdrequest = urllib.request.Request (url=' https://zz.lianjia.com/ditiezufang/li110460711s3320024453090127/rt200600000001/',) Headers= {'User-Agent':user_agent.get_user_agent_pc ()}) response = urllib.request.urlopen (request) html_x = le.HTML (response.read ()) data = html_x.xpath (' / / div [@ class= "content__list"] / / div [@ class= "content__list--item"] [1] / / text ()') data1 = html_x.xpath ('/ / div [@ class= "content__list] / / div [@ class= "content__list--item"] [2] / / text ()') print (data) print (data1) Thank you for reading The above is the content of "python strange xpath bug example analysis". After the study of this article, I believe you have a deeper understanding of python's strange xpath bug example analysis of this problem, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!