爬虫scrapy框架爬不出来,但是request可以出来,能不能帮忙看一下问题遇到的现象和发生背景
from scrapy.spiders import CrawlSpider
from scrapy.selector import Selector
from scrapy.http import Request
from zhuanti.items import ZhuantiItem
class zhuanti(CrawlSpider):
name = 'zhuanti'
start_urls=['https://www.jianshu.com/recommendations/collections?page=1&order_by=hot']
def parse(self,response):
item=ZhuantiItem()
selector=Selector(response)
infos=selector.xpath('//div[@class="col-xs-8"]')
for info in infos:
try:
name=info.xpath('//div/a/h4/text()').extract()[0]
content=info.xpath('//div/a/p/text()').extract()[0]
article=info.xpath('//div/div/a/text()').extract()[0]
fans = info.xpath('//div/div/text()').extract()[0]
item['name']=name
item['content'] = content
item['article'] = article
item['fans'] = fans
yield item
except IndexError:
pass
urls=['https://www.jianshu.com/recommendations/collections?page={}&order_by=hot'.format(str(a))for a in range(2,39)]
for url in urls:
yield Request(url,callback=self.parse)
settings:
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36'
ROBOTSTXT_OBEY = False
FEED_URI='file:D:\AppStore\zhuanti.csv'
FEED_FORMAT='csv'
报错
2022-05-06 00:02:02 [scrapy.utils.log] INFO: Scrapy 2.6.1 started (bot: zhuanti)
2022-05-06 00:02:02 [scrapy.utils.log] INFO: Versions: lxml 4.6.3.0, libxml2 2.9.5, cssselect 1.1.0, parsel 1.6.0, w3lib 1.22.0, Twisted 20.3.0, Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)], pyOpenSSL 22.0.0 (OpenSSL 1.1.1n 15 Mar 2022), cryptography 36.0.2, Platform Windows-10-10.0.19041-SP0
2022-05-06 00:02:02 [scrapy.crawler] INFO: Overridden settings:
{'BOT_NAME': 'zhuanti',
'DOWNLOAD_DELAY': 0.5,
'NEWSPIDER_MODULE': 'zhuanti.spiders',
'SPIDER_MODULES': ['zhuanti.spiders'],
'USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36'}
2022-05-06 00:02:02 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.selectreactor.SelectReactor
2022-05-06 00:02:02 [scrapy.extensions.telnet] INFO: Telnet Password: 8d77413cfb4deb45
2022-05-06 00:02:02 [py.warnings] WARNING: C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\scrapy\extensions\feedexport.py:289: ScrapyDeprecationWarning: The `FEED_URI` and `FEED_FORMAT` settings have been deprecated in favor of the `FEEDS` setting. Please see the `FEEDS` setting docs for more details
exporter = cls(crawler)
2022-05-06 00:02:02 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.feedexport.FeedExporter',
'scrapy.extensions.logstats.LogStats']
2022-05-06 00:02:02 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
'scrapy.downloadermiddlewares.retry.RetryMiddleware',
'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware',
'scrapy.downloadermiddlewares.stats.DownloaderStats']
2022-05-06 00:02:02 [scrapy.middleware] INFO: Enabled spider middlewares:
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
'scrapy.spidermiddlewares.referer.RefererMiddleware',
'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
'scrapy.spidermiddlewares.depth.DepthMiddleware']
2022-05-06 00:02:02 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2022-05-06 00:02:02 [scrapy.core.engine] INFO: Spider opened
2022-05-06 00:02:02 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2022-05-06 00:02:02 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2022-05-06 00:02:14 [filelock] DEBUG: Attempting to acquire lock 1699218188328 on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/publicsuffix.org-tlds\de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Lock 1699218188328 acquired on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/publicsuffix.org-tlds\de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Attempting to acquire lock 1699218187824 on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/urls\62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Lock 1699218187824 acquired on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/urls\62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Attempting to release lock 1699218187824 on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/urls\62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Lock 1699218187824 released on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/urls\62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Attempting to release lock 1699218188328 on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/publicsuffix.org-tlds\de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Lock 1699218188328 released on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/publicsuffix.org-tlds\de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
2022-05-06 00:02:14 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.jianshu.com/recommendations/collections?page=1&order_by=hot> (referer: None)
2022-05-06 00:02:14 [scrapy.core.engine] INFO: Closing spider (finished)
2022-05-06 00:02:14 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 282,
'downloader/request_count': 1,
'downloader/request_method_count/GET': 1,
'downloader/response_bytes': 9105,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'elapsed_time_seconds': 11.793553,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2022, 5, 5, 16, 2, 14, 359618),
'httpcompression/response_bytes': 26418,
'httpcompression/response_count': 1,
'log_count/DEBUG': 10,
'log_count/INFO': 10,
'log_count/WARNING': 1,
'response_received_count': 1,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2022, 5, 5, 16, 2, 2, 566065)}
2022-05-06 00:02:14 [scrapy.core.engine] INFO: Spider closed (finished)
大家看看能不能解决一下