import scrapy
class QiubaiSpider(scrapy.Spider):
name = 'qiubai'
#allowed_domains = ['www.xxx.com']
start_urls = ['https://www.qiushibaike.com/text/']
def parse(self, response):
# 作者的名称与内容,个人觉得是不是这里有问题?爬虫运行后没有获取到任何数据
div_list = response.xpath('//div[@id="col1 old-style-col1"]/div')
all_data = []
for div in div_list: author = div.xpath('./div/a[1]/h2/text()')[0].extract()
content = div.xpath('./div/span//text()').extract()
content = ''.join(content)
dic = {
'author':author,
'content':content
}
all_data.append(dic)
return all_data
|
|
|
|
|
共 2 个关于本帖的回复 最后回复于 2021-11-2 15:26