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点数解答]