0

I am using Scrapy to scrap a web page. That page is little bit slow. So, first it shows a loading gif icon and then loads the whole page. When I am using Scrapy, it is just taking the loading gif icon. I want to wait for few seconds until the page loads completely.

Language :- Python 2

Code :-

import scrapy
import time


class QuotesSpider(scrapy.Spider):
    name = "quotes"
    download_delay = 15.0

    def start_requests(self):
        urls = [
            'exaple.com'
        ]
        time.sleep(1)
        for url in urls:
            yield scrapy.Request(url=url, callback=self.parse)

    def parse(self, response):
        page = response.url.split("/")[-2]
        filename = 'quotes-%s.html' % page
        with open(filename, 'wb') as f:
            f.write(response.body)
        self.log('Saved file %s' % filename)

example.com is the web page. Whenever I open the output HTML file, it shows me the loading icon only. What is the recommended way to achieve this ?

I am trying to use the time.sleep(1) , but output is same.

I am following this tutorial :- https://doc.scrapy.org/en/latest/intro/tutorial.html

Codieroot
  • 697
  • 2
  • 7
  • 15
  • Some of the links in the comments in https://stackoverflow.com/questions/28767156/wait-until-the-webpage-loads-in-scrapy may help. – AS Mackay Apr 18 '18 at 08:39
  • Is that page a static website or dynamic one rendered by Javascript? If it's latter, they response from scrapy will get only the static document. – CK Chen Apr 20 '18 at 05:54

0 Answers0