Scrapy中不同start_urls的不同解析函数 [英] Different parse function for different start_urls in Scrapy
本文介绍了Scrapy中不同start_urls的不同解析函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Scrapy 可以为每个 start_url 设置不同的解析函数吗?
Can Scrapy set different parse function for every start_urls?
这是一段伪代码:
start_urls = [
"http://111sssssssss.com",
"http://222sssssssssssss.com",
"http://333sssssssssss.com",
"http://444sssssssss.com",
]
def parse_1():
'''some code, this function will crawl http://111sssssssss.com'''
def parse_2():
'''some code, this function will crawl http://222sssssssssssss.com'''
有没有办法做到这一点?
Is there any way to do that?
推荐答案
您可以覆盖/实现 parse_start_url
函数并在那里调用 parse_1
或 parse_2
当 response.url
符合您的条件时(在本例中为正确的 URL).
You can override / implement the parse_start_url
function and there call parse_1
or parse_2
when the response.url
meets your criteria (in this case it is the right URL).
def parse_start_url(response):
if response.url == 'http://111sssssssss.com':
parse_1(response)
if response.url == 'http://222sssssssssssss.com':
parse_2(response)
有关 parse_start_url()
的更多信息,请阅读 文档.
For more information about parse_start_url()
read the documentation.
这篇关于Scrapy中不同start_urls的不同解析函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文