我正在尝试抓取此站点:http://jadopado.com/
首先我想更改货币,所以我尝试了这个:
yield FormRequest.from_response(response,formdata={'cms_handler_name': 'jpintl%3Aon_setUserPreference',
'country_code': 'AE'},
dont_click=True,
callback=self.parse_all_categories)
它不起作用,我收到以美元作为货币的响应。 我什至尝试使用 postman 来做,但没有用 有帮助吗?当您从网站上方栏更改货币时,您可以检查 http 请求。
最佳答案
如果您只设置适当的 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
至此,货币设置成功。
希望对您有所帮助。
关于python - Scrapy 发布请求无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16938762/