爬虫58同城xpath
时间: 2023-09-25 13:17:33 浏览: 90
爬虫58同城使用xpath来解析网页内容,其中的一种用法可以参考以下代码示例:
```
import requests
from lxml import etree
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
}
response = requests.get('http://example.com', headers=headers)
html = response.text
tree = etree.HTML(html)
li_list = tree.xpath('//ul[@class="house-list-wrap"]/li')
for li in li_list:
title = li.xpath('div<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Python爬虫——基于xpath爬取58同城房源信息!](https://blog.csdn.net/weixin_39707478/article/details/110772529)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文