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

爬取二手房信息包括卖点 楼盘 地址 户型 建筑面积 所在楼层 建造年代 单价网址为 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']/text()")[0].strip().split(

def parser(html): doc = etree.HTML(html) # 将html转换为Element对象 out_list = [] for item in doc.xpath("//ul[@class='list-items']/li"): sell_point = item.xpath(".//div[@class='sell-point']/text()")[0].strip() building = item.xpath(".//div[@class='prop-title']/a/text()")[0].strip() address = item.xpath(".//div[@class='details-item']/span[1]/text()")[0].strip() house_type = item.xpath(".//div[@class='details-item']/span[2]/text()")[0].strip() area = item.xpath(".//div[@class='details-item']/span[3]/text()")[0].strip() floor = item.xpath(".//div[@class='details-item']/span[4]/text()")[0].strip() build_year = item.xpath(".//div[@class='details-item']/span[5]/text()")[0].strip() price = item.xpath(".//div[@class='pro-price']/strong/text()")[0].strip() url = item.xpath(".//div[@class='prop-title']/a/@href")[0].strip() out_list.append({ 'sell_point': sell_point, 'building': building, 'address': address, 'house_type': house_type, 'area': area, 'floor': floor, 'build_year': build_year, 'price': price, 'url': url }) return out_list [2024-11-02 08:56:33 | AI写代码神器 | 854点数解答]

相关提问