【发布时间】:2017-05-16 03:47:44
【问题描述】:
我正在尝试从脚本运行一个scrapy spider,而不是像这样从命令终端运行它:
scrapy crawl spidername
在 scrapy 文档中,我找到了以下示例:https://doc.scrapy.org/en/latest/topics/practices.html。
现在,我的代码如下所示:
import scrapy
from scrapy.crawler import CrawlerProcess
from scrapy.loader import ItemLoader
from properties.items import PropertiesItem
class MySpider(scrapy.Spider):
name = "basic"
allowed_domains = ["web"]
start_urls = ['http://www.example.com']
def parse(self, response):
l = ItemLoader(item=PropertiesItem(), response = response)
l.add_xpath('title', '//h1[1]/text()')
return l.load_item()
process = CrawlerProcess({
'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
})
process.crawl(MySpider)
process.start() # the script will block here until the crawling is finished
当我运行此脚本时,我收到以下错误:
文件 “/Library/Python/2.7/site-packages/Twisted-16.7.0rc1-py2.7-macosx-10.11-intel.egg/twisted/internet/_sslverify.py”,第 38 行,在 TLSVersion.TLSv1_1:SSL.OP_NO_TLSv1_1 , AttributeError:“模块”对象没有属性“OP_NO_TLSv1_1”
所以我的问题是:
1) 这是什么错误?我一直无法在网上找到任何示例。
2) 我可以改变什么来让这个脚本运行 scrapy?
更新:
为项目添加了安装包
attrs==16.3.0
Automat==0.3.0
cffi==1.9.1
characteristic==14.3.0
constantly==15.1.0
cryptography==1.7.1
cssselect==1.0.0
enum34==1.1.6
idna==2.2
incremental==16.10.1
ipaddress==1.0.17
lxml==3.7.1
parsel==1.1.0
pyasn1==0.1.9 pyasn1-
modules==0.0.8
pycparser==2.17
PyDispatcher==2.0.5
pyOpenSSL==0.15.1
queuelib==1.4.2
Scrapy==1.3.0 service-
identity==16.0.0
six==1.10.0
tree==0.1.0
Twisted==16.6.0
virtualenv==15.1.0
w3lib==1.16.0 zope.
interface==4.3.3
【问题讨论】:
-
看起来像是 Twisted 的问题。你能粘贴项目中所有包的版本号吗?最好粘贴
pip freeze的输出。 -
这也可能是您使用的 OpenSSL 版本的问题。您可以粘贴您正在使用的 OpenSSL 版本吗?可以的话可以关注this answer更新。
-
其实我觉得你应该把
pyOpenSSL的版本更新为pip install --upgrade pyOpenSSL。 -
它似乎不起作用..我得到和以前一样的错误。