【发布时间】:2022-06-13 02:24:56
【问题描述】:
我的目标是网络抓取此 url 链接并遍历页面。我不断收到一个奇怪的错误。我的代码和错误如下:
import requests
import json
import pandas as pd
url = 'https://www.acehardware.com/api/commerce/storefront/locationUsageTypes/SP/locations?page='
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:98.0) Gecko/20100101 Firefox/98.0',
}
#create a url list to scrape data from all pages
url_list = []
for i in range(0, 4375):
url_list.append(url + str(i))
response = requests.get(url, headers=headers)
data = response.json()
d = json.dumps(data)
df = pd.json_normalize(d)
错误:
{'items': [{'applicationName': 'ReverseProxy', 'errorCode': 'UNAUTHORIZED', 'message': 'You are Unauthorized to perform the attempted operation. Application access token required', 'additionalErrorData': [{'name': 'OperationName', 'value': 'http://www.acehardware.com/api/commerce/storefront/locationUsageTypes/SP/locations?page=0&page=1'}]}], 'exceptionDetail': {'type': 'Mozu.Core.Exceptions.VaeUnAuthorizedException'}
这对我来说很奇怪,因为我应该能够访问此 url 上的每个页面
具体来说,因为我可以按照链接复制并粘贴 json 数据。有没有办法在没有 api 密钥的情况下抓取这个网站?
【问题讨论】:
-
您好,因为您未经授权。
You are Unauthorized to perform the attempted operation. http://www.acehardware.com/api/commerce/storefront/locationUsageTypes/SP/locations?page=0 Application access token required -
请参考此链接可能会有所帮助stackoverflow.com/a/48427689/13888486
标签: python web-scraping python-requests