scrapy数据解析

import scrapy


class DouSpider(scrapy.Spider):
    name = "dou"
    #allowed_domains = ["www.douban.com"]
    start_urls = ["https://www.douban.com/doulist/113652271/"]

    def parse(self, response):
        div_ = response.xpath('/html/body/div[3]/div[1]/div/div[1]')
        div_list = div_.xpath('./div[contains(@class, "doulist-item")]')
        for div in div_list:
            # print(div)
            print(div)
            name = div.xpath('./div/div[2]/div[2]/a/text()')[0].extract()
            content = div.xpath('./div/div[2]/div[4]/text()').extract_first()
            print(name ,content)
posted @ 2024-03-02 11:25  会秃头的小白  阅读(3)  评论(0编辑  收藏  举报