我该如何自动扩展整个网页以用pandas(Python)刮擦?

发布于 2025-01-31 02:50:03 字数 663 浏览 1 评论 0原文

我正在尝试从 https://coinmarketcap.com/exchanges/exchanges/binance/binance/ )。在页面上,有一个“负载更多”按钮。单击此点时,将显示更多的行,但URL不会更改。当我使用pd.read_html(url(>)将此URL传递给PANDAS时,它会拉出前100行,而无需其他。如何通过url或命令自动加载所有表?任何帮助都将受到赞赏。 代码:

import json
import requests
import pandas as pd
from bs4 import BeautifulSoup
import lxml
import html5lib


url = "https://coinmarketcap.com/exchanges/binance/"


df = pd.read_html(url)
pd.set_option("display.max_rows", None, "display.max_columns", None)
print(df)

I am trying to scrape html tables from https://coinmarketcap.com/exchanges/binance/ . On the page, there is a "load more" button. When this is clicked, more rows are displayed, but the URL doesn't change. When I pass this URL to pandas using pd.read_html(url(, it pulls the first 100 rows and nothing else. How do I auto load all the tables, either through the URL or through a command? Any help is appreciated.
Code:

import json
import requests
import pandas as pd
from bs4 import BeautifulSoup
import lxml
import html5lib


url = "https://coinmarketcap.com/exchanges/binance/"


df = pd.read_html(url)
pd.set_option("display.max_rows", None, "display.max_columns", None)
print(df)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↘人皮目录ツ 2025-02-07 02:50:03

是的,由于所有结果已加载,URL不会更改,默认情况下没有显示它们以节省加载时间。
您很可能需要创建一个脚本,该脚本会在出现时继续单击“更多负载”,然后运行刮板。

Yes the URL does not change as all the results are loaded, they are just not displayed by default to save load time probably.
You most likely need to create a script which will keep clicking 'load more' whenever it appears and then run your scraper.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文