我正在使用scrapy来抓取我拥有的旧站点,我正在使用下面的代码作为我的蜘蛛。我不介意为每个网页输出文件,或者一个包含所有内容的数据库。但我确实需要让蜘蛛爬行整个事情,而不是我必须把我现在必须做的每一个网址
import scrapy
class DmozSpider(scrapy.Spider):
name = "dmoz"
allowed_domains = ["www.example.com"]
start_urls = [
"http://www.example.com/contactus"
]
def parse(self, response):
filename = response.url.split("/")[-2] + '.html'
with open(filename, 'wb') as f:
f.write(response.body)
要对整个站点进行爬网,应该使用CrawlSpider而不是
scrapy.Spider
Here's an example
出于您的目的,请尝试使用以下方法:
另外,看看这个article
相关问题 更多 >
编程相关推荐