I want to Scrape Comments from https://m.youtube.com
When I tried to scrape https://m.youtube.com, first its Redirecting me to https://www.youtube.com. I've programmed my spider to not obey the robot.txt, disabled cookies, tried meta=dont_redirect. Now its not redirecting me to https://www.youtube.com but now i get response "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" How Can I solve this.
My Spider Code is below:
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)}
'''
Output:
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)
According to Scrapy documentation you can use the
handle_httpstatus_listspider attribute.In your case: