python - 使用带参数的 Scrapyd

标签 python web-scraping scrapy scrapyd

我正在使用 Scrapyd 将 scrapy 用作网络服务。

我想使用带有如下参数的 curl 命令:

curl http://myip:6800/schedule.json -d project=default -d spider=myspider -d domain=www.google.fr

但是我不知道如何获取爬虫中的参数域。

import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor

class MyItem(Item):
    url = Field()

class HttpbinSpider(CrawlSpider):

    name = "expired"
    start_urls = [domain]

有时我需要在参数中传递一个域或多个域

谢谢!

最佳答案

由于 scrapy 中缺少一个特性,这是不可能的。

用户通常通过序列化 curl 的参数来解决这个问题 然后在蜘蛛的 init() 中反序列化。

curl http://myip:6800/schedule.json -d project=default -d spider=myspider -d domains='["www1.example.com", "www2.example.com"]'

代码:

class MySpider(Spider):
    def __init__(self, domains=None):
        domains = json.loads(domains)
        # do something with domains...

关于python - 使用带参数的 Scrapyd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35913285/

相关文章:

python - python中for循环内的递归调用不会在预期的位置退出

python - 如何运行多个 scrapyd 服务器?

authentication - 如何使用python Scrapy爬取Factiva数据?

python - 复杂的排序,使用 cmp 函数很容易完成,但我如何为 Python 3 做计划?

python - 如何连接具有不相等行数和不同列名的数据框

用于 if/then/else 的 Python/pandas 习语

python - 在 Python 中使用 BeautifulSoup 从 HTML 文本中的嵌套元素中获取文本

ruby - 从 HTML 中抓取轨道数据?

python - 循环单击表中的 anchor 标记,但使用 css 选择器 python selenium

python - 设置 restrict_xpaths 设置后出现 UnicodeEncodeError