Home > database >  AttributeError: 'LXML. Etree. _ElementUnicodeResult' object has no attribute 'xpat
AttributeError: 'LXML. Etree. _ElementUnicodeResult' object has no attribute 'xpat

Time:10-11

The import requests
The import time
The from LXML import etree
Def spiders (url, d, pages) :
Headers={' the user-agent ':' Mozilla/5.0 (Macintosh; Intel Mac OS X 10 _15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 '}

For k, v in d.i tems () :
For pg in range (1, + 1) pages:
New_url=+ '/' url '/' +, k + + STR (pg) + '/# contentlist'
HTML=requests. Get (new_url, headers=headers)

Print (HTML. Status_code)
If the HTML status_code!=200:
Break
Time. Sleep (2)
The selector=etree. HTML (HTML. Text)

House_list=selector. Xpath ('//* [@ id="content"]/div [1]/div [1]/div [1]/div/p [2]/text () [3] ')
For house in house_list:
Area=house. Xpath (' div/p [2]/text () ') [4]
Print (area)

If __name__=="__main__ ':
Url='https://dg.lianjia.com/zufang/'
Dg={' dalangzhen ':' DaLang town ', 'nanchengqu' : 'area'}
Spiders (url, dg, 2)


After the output error AttributeError: 'LXML. Etree. _ElementUnicodeResult' object has no attribute 'xpath, is the solution, please?
  • Related