scrapy爬虫实战(部分源代码)

items.py

python 复制代码
# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy


class Sss1Item(scrapy.Item):
    # define the fields for your item here like:
    name = scrapy.Field()

spider_title.py

python 复制代码
import scrapy
from sss1.items import Sss1Item
class SpiderTitleSpider(scrapy.Spider):
    name = "spider_title"
    allowed_domains = ["www.zongheng.com"]
    start_urls = ["https://read.zongheng.com/chapter/1215341/68208370.html"]

    def parse(self, response):
        item=Sss1Item()
        f=open('我有一剑.txt','a',encoding='utf8')
        titles=response.xpath('//*[@id="Jcontent"]/div/div[1]/div[2]/text()').extract()
        for asd in titles:
            f.write(asd+"\n")

        names=[each.extract() for each in response.xpath('//*[@id="Jcontent"]/div/div[4]/p[3]/span[1]/text()')]
        # for asd in names:
        #     f.write(asd+"\n")
        item['name']=names
        yield item
        next=response.xpath('//*[@id="page_reader"]/div[3]/div[1]/div[3]/div[1]/a[3]/@href').get()
        next=next.replace("?","")
        print('----------------------------------------------------------')
        print(next)
        if next:
            yield scrapy.Request(url=next,callback=self.parse)
相关推荐
橘猫云计算机设计2 小时前
ASP.NET图书馆借阅系统(源码+lw+部署文档+讲解),源码可白嫖!
java·数据库·后端·爬虫·小程序·毕业设计·asp.net
小白学大数据6 小时前
如何避免Python爬虫重复抓取相同页面?
开发语言·爬虫·python·php
q5673152312 小时前
使用Pholcus编写Go爬虫示例
开发语言·爬虫·golang
Hotlogin13 小时前
基于分布式指纹引擎的矩阵运营技术实践:突破平台风控的工程化解决方案
分布式·爬虫·线性代数·矩阵
q5673152319 小时前
C#编写HttpClient爬虫程序示例
开发语言·爬虫·python·c#
攻城狮7号1 天前
Python爬虫第5节-urllib的异常处理、链接解析及 Robots 协议分析
爬虫·python·python爬虫
一只专注api接口开发的技术猿1 天前
京东API智能风控引擎:基于行为分析识别恶意爬虫与异常调用
大数据·开发语言·前端·爬虫
励志成为大佬的小杨1 天前
爬虫中遇到的问题
爬虫
电商数据girl1 天前
Taobao商品数据采集方案:官方API与非官方接口实战
爬虫·python·信息可视化
码界筑梦坊1 天前
基于Python的招聘推荐数据可视化分析系统
开发语言·爬虫·python·信息可视化·数据分析