gpt4 book ai didi

python - Scrapy 调试 : Crawled (200)

转载 作者:行者123 更新时间:2023-11-28 16:30:45 25 4
gpt4 key购买 nike

我正在尝试使用 Scrapy 和 XPath 选择器抓取网页。我已经使用 chrome 测试了我的 XPath 选择器。看来我的蜘蛛抓取了零个页面并抓取了 0 个项目。我该怎么做才能纠正它?我从抓取中得到以下输出:

$ scrapy crawl stack
2015-08-24 21:11:55 [scrapy] INFO: Scrapy 1.0.3 started (bot: stack)
2015-08-24 21:11:55 [scrapy] INFO: Optional features available: ssl, http11
2015-08-24 21:11:55 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'st
ack.spiders', 'SPIDER_MODULES': ['stack.spiders'], 'BOT_NAME': 'stack'}
2015-08-24 21:11:56 [scrapy] INFO: Enabled extensions: CloseSpider, TelnetConsole, LogStats, CoreStats, SpiderState
2015-08-24 21:11:56 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddleware, HttpCompressionMiddleware, RedirectMiddleware, CookiesMiddleware, ChunkedTransferMiddleware, DownloaderStats
2015-08-24 21:11:56 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2015-08-24 21:11:56 [scrapy] INFO: Enabled item pipelines:
2015-08-24 21:11:56 [scrapy] INFO: Spider opened
2015-08-24 21:11:56 [scrapy] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2015-08-24 21:11:56 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023
2015-08-24 21:11:56 [scrapy] DEBUG: Crawled (200) <GET http://www.cofman.com/search.php?country=DK#areaid=100001&areatxt=Danmark&country=DK&zoom=6&startDate=2015-08-29&endDate=2015-09-05&fuzzy=false> (referer: None)
2015-08-24 21:11:56 [scrapy] DEBUG: Scraped from <200 http://www.cofman.com/search.php?country=DK>
{'by': [], 'husnr': [], 'periode': [], 'pris': []}
2015-08-24 21:11:56 [scrapy] INFO: Closing spider (finished)
2015-08-24 21:11:56 [scrapy] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 233,
'downloader/request_count': 1,
'downloader/request_method_count/GET': 1,
'downloader/response_bytes': 6059,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2015, 8, 24, 19, 11, 56, 875000),
'item_scraped_count': 1,
'log_count/DEBUG': 3,
'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(2015, 8, 24, 19, 11, 56, 390000)}
2015-08-24 21:11:56 [scrapy] INFO: Spider closed (finished)

这是我的蜘蛛:

from scrapy import Spider
from scrapy.selector import Selector

from stack.items import StackItem


class StackSpider(Spider):
name = "stack"
allowed_domains = ["cofman.com"]
start_urls = [
"http://www.cofman.com/search.php?country=DK#areaid=100001&areatxt=Danmark&country=DK&zoom=6&startDate=2015-08-29&endDate=2015-09-05&fuzzy=false",
]

def parse(self, response):
questions = Selector(response).xpath('//*[@id="content"]/div[4]')

for question in questions:
item = StackItem()
item['husnr'] = question.xpath(
'//*[@id="resultListning"]/div/div/div[1]/a/small').extract()
item['pris'] = question.xpath(
'//*[@id="resultListning"]/div/div/div[5]/div/div[1]//*/span[@class="formatted_price"]').extract()
item['by'] = question.xpath(
'//*[@id="resultListning"]/div/div/div[1]/a/text()').extract()
item['periode'] = question.xpath(
'//*[@id="mapNavigation"]/table/tbody/tr/td[1]/div/text()').extract()
yield item

最后是我的 items.py:

from scrapy.item import Item, Field


class StackItem(Item):
husnr = Field()
pris = Field()
by = Field()
periode = Field()

最佳答案

Scrapy 运行良好。但是,您尝试抓取的页面通过 Javascript 获取其内容。 Scrapy 永远不会得到你想要抓取的内容。

>>> Selector(response).xpath('//div[@id="resultListning"]').extract()
[u'<div id="resultListning"></div>']

您需要找出它从何处获取数据并从该来源获取数据,或者您需要使用各种呈现 JS 的方法中的任何一种。

关于python - Scrapy 调试 : Crawled (200),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32190222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com