最近刚接触scrapy框架,学了一天之后直接用爬小说练手,有不妥之处愿大佬多多指点
新笔趣阁地址:
https://www.xbiquge.la/
spiders中的xbiquge.py
from time import sleep
import scrapy
import re
class XbiqugeSpider(scrapy.Spider):
name = 'xbiquge'
allowed_domains = ['biquge7.com'] #根据需要更改
#下面的网页地址为小说的第一章的url
start_urls = ['https://www.biquge7.com/book/5/1.html'] #可以更改
def parse(self, response):
item ={
}
# title = response.xpath("//div[@class='bookname']/h1/text()").extract_first()
title = response.xpath("//div[@class='content']/h1/text()").extract_first()
print(title)
#如果标题不符合正常的定义规则,则需要自定义
#此处注释的都是以前爬的时候自己定义的
# item["title"] = title.replace('京察风云 ','')
# item["title"] = re.findall('(?<=\.).*$',title)[0]
try:
id = re.findall(r'\d+'