主卧

(64)-- 爬取58同城网页信息

筅森魡賤 提交于 2019-12-08 21:58:07
# 爬取58同城租房信息 from lxml import etree import requests base_url = 'http://bj.58.com/chuzu/?utm_source=market&spm=b-31580022738699-me-f-862.mingzhan&PGTID=0d100000-0000-17cd-3f99-94d590fc655b&ClickID=1' response = requests.get(base_url) html = response.text html = etree.HTML(html) # 找到所有房源li li_list = html.xpath('//ul[@class="listUl"]/li') for li in li_list: # 从一个房源中提取具体信息 title = li.xpath('.//h2/a/text()') if title: title = title[0].strip() else: continue square = li.xpath('.//p[1]/text()')[0].replace(' ','').replace('\xa0','') print(title,square) # 爬取结果如下: C:\Users\cz\AppData\Local\Programs