【发布时间】:2017-02-07 19:10:06
【问题描述】:
我是 Python 的 Scrapy 新手。我需要提取网址的标题而不是上下文。下面的代码将内容连同标题一起提取出来。请在上面提供帮助
提前谢谢你。
class BlogSpider(scrapy.Spider):
name = 'bg'
start_urls = ['https://blog.scrapinghub.com', 'https://scrapinghub.com/']
def parse(self, response):
for title in response.css('h2.entry-title'):
yield {'title': title.css('a ::text').extract_first()}
page = response.url.split("/")[-2]
filename = 'urltitle-%s.html' %page
with open(filename,'wb') as f:
f.write(response.body)
【问题讨论】: