我正在尝试使用scrapy从copyright-gov网站获取数据。这是我的蜘蛛:
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from scrapy.http import FormRequest, Request
from scrapy.utils.response import open_in_browser
class CopyrightSpider(BaseSpider):
name = "copyright_records"
start_url = ["http://cocatalog.loc.gov/cgi-bin/Pwebrecon.cgi?DB=local&PAGE=First"]
def parse(self, response):
yield FormRequest.from_response(response,
formname='querybox',
formdata={'Search_Arg': 'walt disney', 'Search_Code': 'Command Keyword'},
callback=self.parse1)
def parse1(self, response):
open_in_browser(response)
运行抓取工具时我没有收到错误但是我看到有0个网页被抓取:
2015-03-30 15:01:08-0700 [scrapy] INFO: Scrapy 0.24.5 started (bot: copyright_records)
2015-03-30 15:01:08-0700 [scrapy] INFO: Optional features available: ssl, http11
2015-03-30 15:01:08-0700 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'copyright_records.spiders', 'SPIDER_MODULES': ['copyright_records.spiders'], 'BOT_NAME': 'copyright_records'}
2015-03-30 15:01:08-0700 [scrapy] INFO: Enabled extensions: LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, SpiderState
2015-03-30 15:01:08-0700 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddleware, HttpCompressionMiddleware, RedirectMiddleware, CookiesMiddleware, ChunkedTransferMiddleware, DownloaderStats
2015-03-30 15:01:08-0700 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2015-03-30 15:01:08-0700 [scrapy] INFO: Enabled item pipelines:
2015-03-30 15:01:08-0700 [copyright_records] INFO: Spider opened
2015-03-30 15:01:08-0700 [copyright_records] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2015-03-30 15:01:08-0700 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023
2015-03-30 15:01:08-0700 [scrapy] DEBUG: Web service listening on 127.0.0.1:6080
2015-03-30 15:01:08-0700 [copyright_records] INFO: Closing spider (finished)
2015-03-30 15:01:08-0700 [copyright_records] INFO: Dumping Scrapy stats:
{'finish_reason': 'finished',
'finish_time': datetime.datetime(2015, 3, 30, 22, 1, 8, 867056),
'log_count/DEBUG': 2,
'log_count/INFO': 7,
'start_time': datetime.datetime(2015, 3, 30, 22, 1, 8, 865055)}
2015-03-30 15:01:08-0700 [copyright_records] INFO: Spider closed (finished)
不确定为什么它不起作用,任何帮助将不胜感激,谢谢!
答案 0 :(得分:0)
这只是一个错字。
替换:
start_url = ["http://cocatalog.loc.gov/cgi-bin/Pwebrecon.cgi?DB=local&PAGE=First"]
使用:
start_urls = ["http://cocatalog.loc.gov/cgi-bin/Pwebrecon.cgi?DB=local&PAGE=First"]
# HERE^