python - Scrapy:简单项目
问题描述
我想开始一个简单的scrapy项目。它是 Visual Studio 的一个 python 项目。VS 在管理模式下运行。不幸的是, parse(...) 从未被调用,但应该..
import scrapy
from scrapy.crawler import CrawlerProcess
import logging
class BlogSpider(scrapy.Spider):
name = 'blogspider'
start_urls = ['https://blog.scrapinghub.com']
def parse(self, response):
for title in response.css('.post-header>h2'):
yield {'title': title.css('a ::text').extract_first()}
for next_page in response.css('div.prev-post > a'):
yield response.follow(next_page, self.parse)
logging.error("this should be printed")
process = CrawlerProcess({
'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
})
process.crawl(BlogSpider)
process.start()
print("ready")
编辑:我的输出:
2018-09-22 08:23:02 [scrapy.utils.log] INFO: Scrapy 1.5.1 started (bot: scrapybot)
2018-09-22 08:23:02 [scrapy.utils.log] INFO: Versions: lxml 4.2.5.0, libxml2 2.9.5, cssselect 1.0.3, parsel 1.5.0, w3lib 1.19.0, Twisted 18.7.0, Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)], pyOpenSSL 18.0.0 (OpenSSL 1.1.0i 14 Aug 2018), cryptography 2.3.1, Platform Windows-10-10.0.17134-SP0
2018-09-22 08:23:02 [scrapy.crawler] INFO: Overridden settings: {'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'}
2018-09-22 08:23:02 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.logstats.LogStats']
ready
注意:Twisted 来自https://www.lfd.uci.edu/~gohlke/pythonlibs/。
解决方案
推荐阅读
- protocol-buffers - “google.protobuf.Timestamp”未使用 Protobuf v2 定义
- azure - 获取模型时出错:无法在 Azure ADT 资源管理器中刷新访问令牌
- java - 如何在 Java JEditorPane 中自动将小写字母字符更新为大写字母?
- salesforce - 具有共享功能的 Salesforce Lightning 组件不起作用
- javascript - 如何更改将根据 document.referrer 加载的 URL
- go - Reflect Value.Interface() panic: bad indir on CGo type after v1.15.4
- java - 如何向 OutputStream 发送内容
- ios - 该等式将无法迅速解决此错误的原因
- r - 数据集中子集的线性回归模型?
- qt - 调整大小时如何使 QTreeWidget 调用 sizeHint?