feapder python 爬取豆瓣读书 详情页面

python · 2023-07-13
feapder python 爬取豆瓣读书 详情页面

请输入图片描述

# -*- coding: utf-8 -*-
"""
Created on 2023-07-13 15:54:59
---------
@summary:
---------
@author: yangxin
"""

import feapder


class DoubanBookSpider(feapder.AirSpider):
    def start_requests(self):
        yield feapder.Request("https://book.douban.com/subject/36415409/?icn=index-latestbook-subject")

    def parse(self, request, response):
        # 提取网站title
        print(response.xpath('//*[@id="wrapper"]/h1/span/text()').extract_first())
        print(response.xpath('//*[@id="content"]/div/div[1]/div[1]/div[3]/ul/li[2]/a/@href').extract_first().strip('new_review')) #URL
        print(response.xpath('//*[@id="wrapper"]/h1/span/text()').extract_first()) #书名
        print(response.xpath('//*[@id="interest_sectl"]/div/div[2]/strong/text()').extract_first())#评分
        print(response.xpath('//*[@id="link-report"]/div[1]/div/p/text()').extract_first())
        print(response.xpath(".//div[contains( @class ,'indent') and contains( @style, 'display:none')]/text()").extract()) #目录
        print(response.xpath('//*[@id="db-tags-section"]/div/span/a/text()').extract_first()) #标签
        print(response.xpath('//*[@id="mainpic"]/a/img/@src').extract_first()) #封面
        print(response.xpath('.//div[@id="info"]/span/a/text()').extract_first()) #作者



        # 提取网站描述
        #print(response.xpath('.//div[contains( @class ,'indent') and contains( @style, 'display:none')]/text()').extract_first())
        print("网站地址: ", response.url)


if __name__ == "__main__":
    DoubanBookSpider().start()


输出结果

023-07-13 21:31:43.364 | DEBUG    | feapder.network.request:get_response:line:379 | 
                -------------- DoubanBookSpider.parse request for ----------------
                url  = https://book.douban.com/subject/36415409/?icn=index-latestbook-subject
                method = GET
                args = {'timeout': 22, 'stream': True, 'verify': False, 'headers': {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/80.0.3987.87 Safari/537.36'}}
                
美妆帝国蝴蝶牌
https://book.douban.com/subject/36415409/
美妆帝国蝴蝶牌
 8.7 
None
['\n        中文版序', '\n        致谢', '\n        导论', '\n        第一部世纪之交的杭州士绅实验', '\n        第一章无用之用', '\n        第二部制造业知识:1914—1927', '\n        第二章“一份牛脂,两份苏打”:为闺阁准备的配方(1914—1915)', '\n        第三章常识的事业:灭火器(1916—1935)', '\n        第三部物品制造:1913—1942', '\n        第四章中国乌贼与全球流通:家庭工业社', '\n        第五章名中玄妙:从书斋名到商标', '\n        第六章编纂现代工业知识(1930—1941)', '\n        结论', '\n        参考文献', '\n        1. 档案', '\n        2. 出版物及其他引用资料', '\n     · · · · · ·     (', ')\n']
None
https://img2.doubanio.com/view/subject/s/public/s34550893.jpg
[美]林郁沁
网站地址:  https://book.douban.com/subject/36415409/?icn=index-latestbook-subject
2023-07-13 21:31:45.437 | DEBUG    | feapder.core.parser_control:run:line:480 | 等待任务...
2023-07-13 21:31:49.390 | INFO     | feapder.core.spiders.air_spider:run:line:113 | 爬虫被停止

feapder python爬取豆瓣
Theme Jasmine by Kent Liao