1
基本的なScrapyをセットアップして、自分のウェブサイトをクロールし、自分のサイトのすべてのページURLを抽出しようとしています。私はこれがかなり簡単だと思います。ここで私のサイトをクロールしてURLをエクスポートするための治療とxpath - 私は何が間違っていますか?
はチュートリアルからコピーされ、私のitems.pyです:
from scrapy.item import Item, Field
class Website(Item):
name = Field()
description = Field()
url = Field()
こちらのチュートリアルからexample.pyという名前の、私のスパイダーです。私はボットからの復帰に何を得る
from scrapy.spiders import Spider
from scrapy.selector import Selector
from cspenn.items import Website
class DmozSpider(Spider):
name = "cspenn"
allowed_domains = ["christopherspenn.com"]
start_urls = ["http://www.christopherspenn.com/"]
def parse(self, response):
sel = Selector(response)
sites = sel.xpath('//a')
items = []
for site in sites:
item = Website()
item['name'] = site.xpath('a/text()').extract()
item['url'] = site.xpath('a/@href').extract()
item['description'] = site.xpath('text()').re('-\s[^\n]*\\r')
items.append(item)
return items
は次のとおりです。私は間違って何をやっている
scrapy crawl cspenn
2016-04-13 13:15:25 [scrapy] INFO: Scrapy 1.0.5 started (bot: cspenn)
2016-04-13 13:15:25 [scrapy] INFO: Optional features available: ssl, http11, boto
2016-04-13 13:15:25 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'cspenn.spiders', 'SPIDER_MODULES': ['cspenn.spiders'], 'BOT_NAME': 'cspenn'}
2016-04-13 13:15:25 [scrapy] INFO: Enabled extensions: CloseSpider, TelnetConsole, LogStats, CoreStats, SpiderState
2016-04-13 13:15:26 [boto] DEBUG: Retrieving credentials from metadata server.
2016-04-13 13:15:27 [boto] ERROR: Caught exception reading instance data
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/boto/utils.py", line 210, in retry_url
r = opener.open(req, timeout=timeout)
File "/usr/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1227, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
URLError: <urlopen error timed out>
2016-04-13 13:15:27 [boto] ERROR: Unable to read instance data, giving up
2016-04-13 13:15:27 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddleware, HttpCompressionMiddleware, RedirectMiddleware, CookiesMiddleware, ChunkedTransferMiddleware, DownloaderStats
2016-04-13 13:15:27 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2016-04-13 13:15:27 [scrapy] INFO: Enabled item pipelines:
2016-04-13 13:15:27 [scrapy] INFO: Spider opened
2016-04-13 13:15:27 [scrapy] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2016-04-13 13:15:27 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023
2016-04-13 13:15:27 [scrapy] DEBUG: Crawled (200) <GET http://www.christopherspenn.com/> (referer: None)
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] DEBUG: Scraped from <200 http://www.christopherspenn.com/>
{'description': [], 'name': [], 'url': []}
2016-04-13 13:15:27 [scrapy] INFO: Closing spider (finished)
2016-04-13 13:15:27 [scrapy] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 222,
'downloader/request_count': 1,
'downloader/request_method_count/GET': 1,
'downloader/response_bytes': 14302,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2016, 4, 13, 17, 15, 27, 262789),
'item_scraped_count': 93,
'log_count/DEBUG': 96,
'log_count/ERROR': 2,
'log_count/INFO': 7,
'response_received_count': 1,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2016, 4, 13, 17, 15, 27, 77084)}
2016-04-13 13:15:27 [scrapy] INFO: Spider closed (finished)
?私はチュートリアルをほぼ正確に続けました。目的の出力は、タイトル、ページURL、および説明のCSVファイルです。
私は基本的に、サイトのURL全体をきれいにエクスポートします。サイト全体をクロールし、すべてのページURLをエクスポートします。ありがとうございました! –
@ChristopherPenn大丈夫です。一歩一歩進んでみましょう。現在どのような成果を上げていますか?空ではない 'name'と' url'を見ていますか? – alecxe
私はそうです! {'description':[]、 '名前':[マーキングホワイトベルト]、 'url':[u'http://www.christopherspenn.com/buy-the-marketing-white-ベルトブック/ ']} –