Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 解析站点时单击按钮_Python_Selenium_Parsing_Beautifulsoup_Python Requests - Fatal编程技术网

Python 解析站点时单击按钮

Python 解析站点时单击按钮,python,selenium,parsing,beautifulsoup,python-requests,Python,Selenium,Parsing,Beautifulsoup,Python Requests,我正在尝试解析一个表,例如,来自此页面(或任何其他历史快照): 下面的代码成功地解析了该表的前200行 import requests from bs4 import BeautifulSoup response_date = requests.get('https://coinmarketcap.com/historical/20160228/') pastebin_url_date = response_date.text soup_get_date = BeautifulSoup(pa

我正在尝试解析一个表,例如,来自此页面(或任何其他历史快照):

下面的代码成功地解析了该表的前200行

import requests
from bs4 import BeautifulSoup

response_date = requests.get('https://coinmarketcap.com/historical/20160228/')
pastebin_url_date = response_date.text
soup_get_date = BeautifulSoup(pastebin_url_date, 'lxml')

table = soup_get_date.find_all("div", attrs={"class": "cmc-table__table-wrapper-outer"})[2]
table_body = table.find('tbody')
rows = table_body.find_all('tr')

for row in rows:
    cols = row.find_all('td')
    ...
问题是那里有513行,我不知道如何在有这样的按钮时单击“加载更多”按钮。如何在按钮存在时按下“加载更多”按钮?

在这个页面上,“加载更多”按钮必须按下2次(在其他页面上,可能更多,可能更少)。

这些页面是动态加载的,实际上没有“物理”方式来点击带有
bs4
的按钮

但是,有一个API可以查询和循环页面以获取更多数据

注意:我对所有页面中的页面使用了
限制[:3]
;要获取所有数据,只需删除
[:3]
,使其在所有页面中的页面看起来都是

以下是方法:

从urllib.parse导入urlencode
导入请求
查询字符串=[
(“开始”,“1”),
(‘限制’、‘100’),
(‘sortBy’、‘market_cap’),
('sortType','desc'),
(“换算”、“美元”),
('cryptoType','all'),
('tagType','all'),
]
基数=”https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing?"
response=requests.get(f“{base}{urlencode(查询字符串)}”).json()
最后一页=(int(响应[“数据”][“总数”])//100)+1
所有_页面=[1如果i==0,则为1,否则(i*100)+1表示范围内的i(1,最后一个_页面)]
打印(f“有{len(所有页面)}页。”)
结果=[]
对于所有页面中的页面[:3]:
查询字符串=[
(“开始”,str(第页)),
(‘限制’、‘100’),
(‘sortBy’、‘market_cap’),
('sortType','desc'),
(“换算”、“美元”),
('cryptoType','all'),
('tagType','all'),
]
response=requests.get(f“{base}{urlencode(查询字符串)}”).json()
结果:扩展([
[
货币[“名称”],
四舍五入(货币[“报价”][0][“价格”],4),
]
对于响应中的货币[“数据”][“加密货币列表”]
])
打印(“{:10}”。格式(*[“货币”、“值”]))
打印(“\n”.join(“{:10}”.format(*item)(用于结果中的项))
输出:

There are 48 pages.
Currency                           Value
Bitcoin                       49797.3732
Ethereum                       2223.4234
Binance Coin                    496.2642
Tether                            1.0001
XRP                               1.0477
Cardano                            1.113
Dogecoin                          0.2712
Polkadot                         29.6033
Uniswap                          30.6648
Litecoin                        225.2603
Bitcoin Cash                    774.4016
Chainlink                        31.6194
VeChain                           0.1777
Solana                           42.2906
USD Coin                          0.9999
Stellar                           0.4273
Filecoin                        133.4884
THETA                             8.8757
Wrapped Bitcoin                49938.205
TRON                              0.1042
Binance USD                       0.9998
Monero                          388.1286
Terra                            16.4256
Neo                              80.8837
Klaytn                             2.113
EOS                                5.202
IOTA                              1.6668
PancakeSwap                      28.0534
Bitcoin SV                      238.5014
BitTorrent                        0.0067
FTX Token                        45.5833
Crypto.com Coin                   0.1693
Aave                            322.3405
Cosmos                           18.6716
Maker                          3835.4303
Dai                               1.0003
Tezos                             4.5509
Ethereum Classic                 29.5024
Algorand                          1.1523
Huobi Token                      17.2733
Avalanche                        22.1258
Compound                         549.279
Bitcoin BEP2                  49741.0943
Dash                            260.2305

and a lot more ...

这些页面是动态加载的,使用
bs4
点击按钮实际上没有“物理”方式

但是,有一个API可以查询和循环页面以获取更多数据

注意:我对所有页面中的页面使用了
限制[:3]
;要获取所有数据,只需删除
[:3]
,使其在所有页面中的页面看起来都是

以下是方法:

从urllib.parse导入urlencode
导入请求
查询字符串=[
(“开始”,“1”),
(‘限制’、‘100’),
(‘sortBy’、‘market_cap’),
('sortType','desc'),
(“换算”、“美元”),
('cryptoType','all'),
('tagType','all'),
]
基数=”https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing?"
response=requests.get(f“{base}{urlencode(查询字符串)}”).json()
最后一页=(int(响应[“数据”][“总数”])//100)+1
所有_页面=[1如果i==0,则为1,否则(i*100)+1表示范围内的i(1,最后一个_页面)]
打印(f“有{len(所有页面)}页。”)
结果=[]
对于所有页面中的页面[:3]:
查询字符串=[
(“开始”,str(第页)),
(‘限制’、‘100’),
(‘sortBy’、‘market_cap’),
('sortType','desc'),
(“换算”、“美元”),
('cryptoType','all'),
('tagType','all'),
]
response=requests.get(f“{base}{urlencode(查询字符串)}”).json()
结果:扩展([
[
货币[“名称”],
四舍五入(货币[“报价”][0][“价格”],4),
]
对于响应中的货币[“数据”][“加密货币列表”]
])
打印(“{:10}”。格式(*[“货币”、“值”]))
打印(“\n”.join(“{:10}”.format(*item)(用于结果中的项))
输出:

There are 48 pages.
Currency                           Value
Bitcoin                       49797.3732
Ethereum                       2223.4234
Binance Coin                    496.2642
Tether                            1.0001
XRP                               1.0477
Cardano                            1.113
Dogecoin                          0.2712
Polkadot                         29.6033
Uniswap                          30.6648
Litecoin                        225.2603
Bitcoin Cash                    774.4016
Chainlink                        31.6194
VeChain                           0.1777
Solana                           42.2906
USD Coin                          0.9999
Stellar                           0.4273
Filecoin                        133.4884
THETA                             8.8757
Wrapped Bitcoin                49938.205
TRON                              0.1042
Binance USD                       0.9998
Monero                          388.1286
Terra                            16.4256
Neo                              80.8837
Klaytn                             2.113
EOS                                5.202
IOTA                              1.6668
PancakeSwap                      28.0534
Bitcoin SV                      238.5014
BitTorrent                        0.0067
FTX Token                        45.5833
Crypto.com Coin                   0.1693
Aave                            322.3405
Cosmos                           18.6716
Maker                          3835.4303
Dai                               1.0003
Tezos                             4.5509
Ethereum Classic                 29.5024
Algorand                          1.1523
Huobi Token                      17.2733
Avalanche                        22.1258
Compound                         549.279
Bitcoin BEP2                  49741.0943
Dash                            260.2305

and a lot more ...

似乎有一种像Silenium这样的工具来按按钮。api是的,但有我没有的仅用于金钱的历史数据:)请指定,您在哪里找到/v3/api?我经常只找到/v1/*/API,其中*可以是,例如,cryptocurrency(/v1/cryptocurrency/),似乎有一个类似Silenium的工具来按按钮。api是的,但有我没有的仅用于金钱的历史数据:)请指定,您在哪里找到/v3/api?我经常只找到/v1/*/API,其中*下可以是加密货币(/v1/cryptocurrency/)