当我尝试抓取https://m.youtube.com时,首先将我重定向到https://www.youtube.com。我已经对我的蜘蛛进行了编程,使其不服从robot.txt,禁用cookie,尝试了meta=dont_redirect。现在它没有将我重定向到https://www.youtube.com但现在我得到响应“忽略响应 <303 https://m.youtube.com/view_comment?v=xHkL9PU7o9k&gl=US&hl=en&client=mv-google >: HTTP 状态代码未处理或不允许”我该如何解决这个问题。
我的蜘蛛代码如下:
import scrapy
class CommentsSpider(scrapy.Spider):
name = 'comments'
allowed_domains = ['m.youtube.com']
start_urls = [
'https://m.youtube.com/view_comment?
v=xHkL9PU7o9k&gl=US&hl=en&client=mvgoogle'
]
def start_requests(self):
for url in self.start_urls:
yield scrapy.Request(url, meta = {'dont_redirect': True})
def parse(self, response):
x = response.xpath('/html/body/div[4]/div[2]/text()').extract()
y =
response.xpath('/html/body/div[4]/div[3]/div[2]/text()').extract()
yield{'Comments': (x, y)}
'''
输出:
2019-07-18 16:07:23 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023
2019-07-18 16:07:24 [scrapy.core.engine] DEBUG: Crawled (303) <GET https://m.youtube.com/view_comment?v=xHkL9PU7o9k&gl=US&hl=en&client=mv-google> (referer: None)
2019-07-18 16:07:24 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <303 https://m.youtube.com/view_comment?v=xHkL9PU7o9k&gl=US&hl=en&client=mv-google>: HTTP status code is not handled or not allowed
2019-07-18 16:07:24 [scrapy.core.engine] INFO: Closing spider (finished)