酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

爬取二手房信息包括卖点 楼盘 地址 户型 建筑面积 所在楼层 建造年代 单价sellingpoint,communityname, address, housetype,buildingarea, floor,constructionyear,price 网址为 https://dalian.anjuke.com/sale/ 写一下他的解析函数 可以爬取到数据 仿照如下函数格式写 def parser(html): #解析函数 doc=etree.html(html) #html转换为soup对象 out_list=[] for row in doc.xpath("//div[@id='content']//li"): #书名 title=row.xpath(".//h2/a/text()")[0].strip() #评分 score=row.xpath(".//p[@class='rating']/span[2]/text()")[0].strip() #info为作者、出版社、出版日期的列表,通过/分隔 info=row.xpath(".//p[@class='color-gray

def parser(html): doc = etree.HTML(html) out_list = [] for row in doc.xpath("//ul[@class='sale-list']//li"): sellingpoint = row.xpath(".//div[@class='pro-title']/text()")[0].strip() communityname = row.xpath(".//div[@class='house-title']/a/text()")[0].strip() address = row.xpath(".//address/text()")[0].strip() housetype = row.xpath(".//div[@class='details-item'][1]/span[2]/text()")[0].strip() buildingarea = row.xpath(".//div[@class='details-item'][2]/span[2]/text()")[0].strip() floor = row.xpath(".//div[@class='details-item'][3]/span[2]/text()")[0].strip() constructionyear = row.xpath(".//div[@class='details-item'][4]/span[2]/text()")[0].strip() price = row.xpath(".//span[@class='price-det']/text()")[0].strip() out_list.append({ 'sellingpoint': sellingpoint, 'communityname': communityname, 'address': address, 'housetype': housetype, 'buildingarea': buildingarea, 'floor': floor, 'constructionyear': constructionyear, 'price': price }) return out_list [2024-11-02 08:58:39 | AI写代码神器 | 792点数解答]

相关提问