Python中文
首页
教程
问答
标签
搜索
登录
注册
在Scrapy python中向process.crawn传递参数
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我希望得到与此命令行相同的结果: scrapy crawl linkedin_anonymous-a first=James-a last=Bond-o output.json</p> <p>我的剧本如下:</p> <pre><code>import scrapy from linkedin_anonymous_spider import LinkedInAnonymousSpider from scrapy.crawler import CrawlerProcess from scrapy.utils.project import get_project_settings spider = LinkedInAnonymousSpider(None, "James", "Bond") process = CrawlerProcess(get_project_settings()) process.crawl(spider) ## <-------------- (1) process.start() </code></pre> <p>我发现(1)中的process.crawl()正在创建另一个LinkedInAnonymousSpider,其中first和last都不是(在(2)中打印的),如果是,那么就没有创建对象spider的意义,如何能够将参数首先和最后传递给process.crawl()?</p> <p>linkedin匿名:</p> <pre><code>from logging import INFO import scrapy class LinkedInAnonymousSpider(scrapy.Spider): name = "linkedin_anonymous" allowed_domains = ["linkedin.com"] start_urls = [] base_url = "https://www.linkedin.com/pub/dir/?first=%s&last=%s&search=Search" def __init__(self, input = None, first= None, last=None): self.input = input # source file name self.first = first self.last = last def start_requests(self): print self.first ## <------------- (2) if self.first and self.last: # taking input from command line parameters url = self.base_url % (self.first, self.last) yield self.make_requests_from_url(url) def parse(self, response): . . . </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你可以用简单的方法:</p> <pre><code>from scrapy import cmdline cmdline.execute("scrapy crawl linkedin_anonymous -a first=James -a last=Bond -o output.json".split()) </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
文本导入时标题行中的特殊字符
2 回答
文本小部件:在没有输入时更新并在循环后保持空闲
4 回答
文本小部件tkin
9 回答
文本小部件tkinter中的标签更改或文本外观更改是否有撤消功能?
10 回答
文本小部件tkinter复制图像选项
6 回答
文本小部件上的Python Tkinter ttk滚动条未缩放
9 回答
文本小部件上的滚动条可能需要根据制表符ord显示前进行滚动
3 回答
文本小部件不显示lis中的内容
4 回答
文本小部件不显示Unicode字符
5 回答
文本小部件中写入的行间距
8 回答
文本小部件中的文本作为变量
6 回答
文本小部件中的滚动条仅显示在底部
4 回答
文本小部件中的选项卡键空间计数
6 回答
文本小部件作为Lis
4 回答
文本小部件在主框架中扩展列宽
2 回答
文本小部件未使用删除功能清除
3 回答
文本小部件滚动动画(Tkinter、Python)
2 回答
文本居中。格式正确吗?
4 回答
文本差分算法
8 回答
文本已知时音频文件中的单词索引
7 回答