【发布时间】:2021-04-11 01:33:33
【问题描述】:
我需要以美元货币提取一些工资,但我从另一个国家/地区访问该页面,然后显示的货币是当地(瑞尔)货币,没有美元。所以,我发送 cookie 来请求新货币和新国家
在我的设置中:
COOKIES_ENABLED = False
COOKIES_DEBUG = True
在我使用的蜘蛛中:
class HtSpider(scrapy.Spider):
name = 'sells'
allow_domain = ['hattrick.org']
def start_requests(self):
urls = ['https://www.hattrick.org']
for url in urls:
player = 'goto.ashx?path=/Club/Players/Player.aspx?playerId=450940600'
joint = urljoin(url, player)
yield scrapy.Request(
url=joint,
cookies={'currency': 'USD', 'country': 'US'},
# meta={'dont_merge_cookies': True},
dont_filter=True,callback=self.price)
def price(self,response):
price_xpath = response.xpath('//* [@id="transferHistory"]/table//tr[1]/td[6]/text()').extract_first()
print(price_xpath) // it is not in USD but in Riel :(
open_in_browser(response) // to check if it is in Riel or in USD
然后,从我获得的 cookie 调试中:
DEBUG: Sending cookies to: <GET https://www.hattrick.org/en/Club/Players/Player.aspx?playerId=450940600>
Cookie: currency=USD; country=US; currency=USD; country=US; ASP.NET_SessionId=xxxxx
2021-01-05 16:33:13 [scrapy.downloadermiddlewares.cookies] DEBUG: Received cookies from: <200 https://www.hattrick.org/en/Club/Players/Player.aspx?playerId=450940600>
Set-Cookie: InitialOrigin=Origin=direct|&DateSet=2021-01-05 10:33:13;
**Print price: 2 280 000 Riel**
如何获取我在请求中发送的 cookie,而不是来自网站的 cookie?简而言之……如何获得美元而不是瑞尔?
【问题讨论】:
标签: python cookies scrapy request response