- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 pyinstaller 将一个非常简单的爬虫蜘蛛发布为 .exe。
我已经搜索并阅读了我能找到的所有内容,但我仍然无法弄清楚出了什么问题。任何正确方向的帮助或指示都非常有用!
如果我将 yield 更改为 return 它不会给我错误并且可以正常工作,除了它只返回 1 个项目(这是正常的,因为它是 return 而不是 yield。)代码工作得很好,我的 IDE 中没有任何错误(不使用 pyinstaller .exe)
笔记:
我正在使用 pyinstaller 开发版本。
运行我的 .exe 时出错
2020-04-28 11:57:30 [scrapy.core.scraper] ERROR: Spider error processing <GET http://books.toscrape.com/> (referer: None)
Traceback (most recent call last):
File "lib\site-packages\twisted\internet\defer.py", line 1418, in _inlineCallbacks
File "lib\site-packages\scrapy\core\downloader\middleware.py", line 42, in process_request
File "lib\site-packages\twisted\internet\defer.py", line 1362, in returnValue
twisted.internet.defer._DefGen_Return: <200 http://books.toscrape.com/>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "lib\site-packages\scrapy\utils\defer.py", line 55, in mustbe_deferred
File "lib\site-packages\scrapy\core\spidermw.py", line 60, in process_spider_input
File "lib\site-packages\scrapy\core\scraper.py", line 148, in call_spider
File "lib\site-packages\scrapy\utils\misc.py", line 202, in warn_on_generator_with_return_value
File "lib\site-packages\scrapy\utils\misc.py", line 187, in is_generator_with_return_value
File "inspect.py", line 973, in getsource
File "inspect.py", line 955, in getsourcelines
File "inspect.py", line 786, in findsource
OSError: could not get source code
import scrapy
from items import scrapyStandaloneTestItem
class bookSpider(scrapy.Spider):
name = "bookSpider"
custom_settings = {
"FEED_URI" : "resultFile.csv",
"FEED_FORMAT" : "csv",
"FEED_EXPORT_FIELDS" : ["title", "price"]
}
def start_requests(self):
urls = [
"http://books.toscrape.com/",
]
for url in urls:
yield scrapy.Request(url=url, callback=self.parse)
def parse(self, response):
# Getting an instance of our item class
item = scrapyStandaloneTestItem()
# Getting all the article's with product pod class
articles = response.css("article.product_pod")
# Looping thru all the article elements we got earlier
for article in articles:
# Getting the needed values from the site and putting them in variables
title = article.css("a::attr(title)").extract()
price = article.css("p.price_color::text").extract()
# Setting the title / price variables in our items class equal to the variables that we just extracted data in to
item["title"] = title
item["price"] = price
yield item
import scrapy
class scrapyStandaloneTestItem(scrapy.Item):
# define the fields for your item here
title = scrapy.Field()
price = scrapy.Field()
# In this file we will run the spider(s)
from scrapy.crawler import CrawlerProcess
from myBookSpider import bookSpider
from scrapy.utils.project import get_project_settings
def runSpider():
# Running scraper
process = CrawlerProcess(get_project_settings())
process.crawl(bookSpider)
process.start()
if (__name__ == "__main__"):
runSpider()
最佳答案
迟到的答案,但我会为其他人保留它,您所要做的就是将此代码添加到您的蜘蛛中,`
导入scrapy.utils.misc
导入scrapy.core.scraper
def warn_on_generator_with_return_value_stub(spider, callable):
pass
scrapy.utils.misc.warn_on_generator_with_return_value = warn_on_generator_with_return_value_stub
scrapy.core.scraper.warn_on_generator_with_return_value = warn_on_generator_with_return_value_stub`
关于python - Scrapy Pyinstaller OSError : could not get source code/twisted. internet.defer._DefGen_Return,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61478001/
这些指针之间有区别吗?每次通话到底发生了什么。 *p++ (*p)++, *(p)++ 最佳答案 1和3是一样的。 请记住 ++ 的后缀和一元形式。和 --有一个结果和一个副作用: x++ 的结果是
这个问题已经有答案了: difference between grep Vs cat and grep (5 个回答) 已关闭 8 年前。 我看到一个例子,其中有人这样做: cat source.tx
它曾经有效。现在,当我添加一个断点时: saveSnippet: (title, imageUrl, role) => { debugger; ... chrome (
开发.Net Web应用程序时,如果生成运行时错误,则会显示一些在Exception类中找不到的“额外”调试信息。 它显示了“源错误”部分,其中显示了代码摘录,其中行号准确显示了错误的产生位置,并显示
Firefox 中的“源”和“生成的源”有什么区别? 请举例说明。 编辑: 7 月 3 日 “搜索引擎”使用哪个来源,生成的还是生成前的? 最佳答案 Source 将显示页面加载的源(由服务器提供)。
对于具有两个不同工作表的Excel文件,我有两个OLE DB源。工作表A和工作表B。工作表A单元格I6包含日期,我想组合这两个源并在工作表B中添加一列,以将该值设置为工作表A的日期值。有可能做到吗?任
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
这是我的代码: import speech_recognition as sr r = sr.Recognizer() with sr.Microphone() as source: prin
我是 mysql 新手。我正在尝试 setter 工示例数据库 我尝试了 stackoverflow 中提到的一些方法,但没有帮助 谁能告诉我如何解决这个问题 SELECT 'LOADING depa
在终端中,我启动程序如下: 1) source env.sh 2) source activate enviroment 3) program --args 除了在 Pycharm 中并调试代码之外,
IntelliJ 如何知道目录是“源”还是“测试源”?如何始终将目录标记为“测试源”? build.gradle 1 apply plugin: 'java' apply plugin: 'idea'
这个问题类似于Source script to separate environment in R, not the global environment , 但有一个关键的转折。 考虑一个源另一个脚
和有什么区别--devtool source-map & eval-source-map ? 最佳答案 webpack 文档有一个方便的图表,说明这些不同的选项可能适合哪些情况。 他们显示eval-s
这个问题已经有答案了: Issue with virtualenv - cannot activate (36 个回答) 已关闭 4 年前。 venv) C:\Users\Sunil\PycharmP
在以前版本的 Akka Streams 中,groupBy 返回一个 Source 的 Source 可以具体化为一个 Source[Seq [A]]. 在 Akka Streams 2.4 中,我看
这个问题已经有答案了: Issue with virtualenv - cannot activate (36 个回答) 已关闭 4 年前。 venv) C:\Users\Sunil\PycharmP
是否可以获取 Bash 片段的源代码,但仅在特定条件成立时才实际提供其中的函数? 所以我要问的是,我可以无条件地获取目录中的所有文件,但获取的文件包含是否向采购外壳提供功能的逻辑。 例子: .bash
我无法查看 JavaCore.class 源代码,但我可以很好地使用代码。 例如,要查看方法JavaCore.create(..) 的源代码,我ctrl - click(或按f3) 在 JavaCor
-- Sample employee database -- See changelog table for details -- Copyright (C) 2007,2008, MySQL
当我在我的 IDE 中编译项目时它工作正常但是当我在 bamboo 中编译时它给我以下错误。 我已经检查过我在任务中配置的 jdk 版本是 1.6,我还尝试从 pom 中的 maven 插件强制执行
我是一名优秀的程序员,十分优秀!