我想用scrapy刮掉this link。浏览器中的链接指的是另一个http request。在浏览器中直接访问此引用的调用将返回: {" message":"令牌无效或过期"} 。 根据提到的答案here我做了:
scrapy shell
headers= {'X-JadoPado-API-Token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHAiOiJqYWRvcGFkby5jb20iLCJ1c2VySWQiOm51bGwsImV4cCI6MTQ5NDMzMjE0OSwia2lkIjoiYWQxNWY3N2I0NzlmNDIxOTk0OGI5Y2U3MzMyOTQ2MzciLCJkZXZpY2UiOiI3YTc4YzM4Mi01N2VhLTQ3YjItODBiNi1lZTUzYjQ4MzhjNjAifQ.DWrdaIsFCTSAvfk2DEUrdxeloCSNArEk1zDncKlFz0M'}
req = Request("https://jadopado.com/en-sa/mobile-phones/c/4298?filter=&page=2&sorting=-launchedAt", headers=headers)
fetch(req)
headers =
{'Accept':'application/json',
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'en-US,en;q=0.5',
'Cache-Control':'no-cache',
'Connection':'keep-alive',
'Host':'api.jadopado.com',
'Origin':'https://jadopado.com',
'Referer':'https://jadopado.com/en-sa/mobile-phones/c/4298?filter=&page=2&sorting=-launchedAt',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0',
'X-JadoPado-API-Token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHAiOiJqYWRvcGFkby5jb20iLCJ1c2VySWQiOm51bGwsImV4cCI6MTQ5NDMzMjE0OSwia2lkIjoiYWQxNWY3N2I0NzlmNDIxOTk0OGI5Y2U3MzMyOTQ2MzciLCJkZXZpY2UiOiI3YTc4YzM4Mi01N2VhLTQ3YjItODBiNi1lZTUzYjQ4MzhjNjAifQ.DWrdaIsFCTSAvfk2DEUrdxeloCSNArEk1zDncKlFz0M',
'X-JadoPado-Currency':'SAR',
'X-JadoPado-Locale':'en',
}
即使这样也行不通。我是否遗漏了任何东西,或者是否有更好的方法用scrapy刮去link?
答案 0 :(得分:2)
您可能使用了正确的headers
,但没有使用正确的网址。
请参阅Request URL
试试这段代码。
headers = {
'Origin': 'https://jadopado.com',
'Accept-Encoding': 'gzip, deflate, sdch, br',
'Accept-Language': 'en-US,en;q=0.8',
'X-JadoPado-Locale': 'en',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
'X-JadoPado-Currency': 'SAR',
'Accept': 'application/json',
'Cache-Control': 'no-cache',
'DNT': '1',
'Connection': 'keep-alive',
'Referer': 'https://jadopado.com/en-sa/mobile-phones/c/4298?filter=&page=1&sorting=-launchedAt',
'X-JadoPado-API-Token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHAiOiJqYWRvcGFkby5jb20iLCJ1c2VySWQiOm51bGwsImV4cCI6MTQ5NDMzNTAzOSwia2lkIjoiYWMxOWM0YTFlY2FhNDA2MGE5ZjEwYjE1ZGQ3ZmUzZjMiLCJkZXZpY2UiOiJhNDQ4YWFmOS0zMDI0LTQ1NGQtOTg0MC0zYzMxZGI1YzcwMDcifQ.2m2VQ13owO0kLy8shcLuzuAPE8iNEsPEA0p4x640K8o',
}
yield Request('https://api.jadopado.com/v1/categories/?parentId=4298&page=1&recordsPerPage=500&showFee=true', headers=headers)