请求分页后?

2024-03-29 14:40:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我想得到这些交易: https://www.omniexplorer.info/address/1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA

第一页没有问题:

import requests

headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
}

data = [('addr', '1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA')]

response = requests.post('https://api.omniexplorer.info/v1/address/addr/details/', headers=headers, data=data)

response = response.json()

print(response["transactions"])

但是我怎么能称之为第二页呢?在

我试过使用params“params={'page':2}”,但是没有用

谢谢你的帮助!在

问候


Tags: httpsimportinfodataaddressresponsewwwtype
2条回答

你应该认为这可能是一种宁静,然后你就会知道怎么做了

import requests

headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
}
pj = {}

for page in range(1,3):
    data = [('addr', '1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA'),('page',page)]
    response = requests.post('https://api.omniexplorer.info/v1/address/addr/details/', headers=headers , data = data)
    response = response.json()
    print(response)
    pj[page] = response["transactions"]
value = list(pj.values())
print(value[0] == value[1])

对于所使用的API,应将页码作为表单值发送:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "page=19" "https://api.omniexplorer.info/v1/properties/gethistory/3"

如果将page=19替换为page=20,您将看到第二个调用只有三个条目,而第一个调用有十个条目。

使用请求,应该是这样的:

^{pr2}$

或者,用你自己的例子,而不是我在他们的网页上找到的例子:

import requests

headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
}

data = {
    'addr': '1FoWyxwPXuj4C6abqwhjDWdz6D4PZgYRjA',
    'page': 1,
}

response = requests.post('https://api.omniexplorer.info/v1/address/addr/details/',
                         headers=headers, data=data)

相关问题 更多 >