python - Scrapy a website that need use cookies -


I am creating a scrap to scrap a website, but this website is working with cookies, I do not I know how I can make instructions to scrape the website's data by using cookies.

  class dmozspider (spider): name = "dmoz" allowed_domains = ["dmoz.org "] Start_urls = [" http: //Www.dmoz.org/Computers/Programming/Languages/Python/Books/ "] DRF Pars (self, response): cell = selector (Re: =) Site = sel.HtmlXPathSelector ('// ul [@ class = "directory-url"] / Li') Item = [] For sites in the sites: items = website () item ['name'] = site. xpath ('a / text ()'). Remove () item ['url'] = site Exped ('a / @ href'). Remove () items. Upload (item) return item   

How can I add cookies to this URL correctly

@ omair_77, you can override your spider's start_requests method to add cookies. Initial request by your spider:

  def start_reques ts (self): return [request (url = "http://www.example.com", cookies = {'currency': 'USD', 'country': 'you' })   

In this way, your spider The first request of the person will be with those cookies, and your parse method will be with the first response.



Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -