2013-06-05 161 views
1

我想抓取這個網站:http://jadopado.com/Scrapy POST請求不工作

首先我要改變貨幣,所以我嘗試這樣做:

yield FormRequest.from_response(response,formdata={'cms_handler_name': 'jpintl%3Aon_setUserPreference', 
              'country_code': 'AE'}, 
           dont_click=True, 
           callback=self.parse_all_categories) 

它不工作,我得到的以美元作爲貨幣的迴應。 我甚至試圖用郵遞員做它,但它不工作 任何幫助?您可以在網站上部欄更改貨幣時檢查http請求。

回答

4

如果你只是設置相應的cookie customer_country_code,像這樣:

from scrapy.http import Request 
from scrapy.selector import HtmlXPathSelector 
from scrapy.spider import BaseSpider 


class ExampleSpider(BaseSpider): 
    name = 'example' 
    allowed_domains = ['jadopado.com'] 

    def start_requests(self): 
     yield Request(url='http://jadopado.com/', cookies={'customer_country_code': 'AE'}) 

    def parse(self, response): 
     hxs = HtmlXPathSelector(response) 

     print hxs.select("//div[@class='country_code']/text()").extract()[0] 

打印:

AED

所以,貨幣設置成功。

希望有所幫助。

+0

工作:)謝謝:) 但你有什麼想法爲什麼其他方法不起作用? – Vanddel