无法在Python中获取BS4表内容
我想获取此链接中存在的所有用户处理/a>
这是尝试的代码,
import requests
from bs4 import BeautifulSoup
URL = 'https://practice.geeksforgeeks.org/leaderboard/'
def getdata(url):
r = requests.get(url)
return r.text
htmldata = getdata(URL)
soup = BeautifulSoup(htmldata, 'html.parser')
table= soup.find_all('table',{"id":"leaderboardTable"})
print(table[0].find_all('tbody')[1])
print(table[0].find_all('tbody')[1].tr)
输出:
<tbody id="overall_ranking">
</tbody>
None
代码正在获取表,但是当我尝试打印表中存在的TR或TD标签时,它没有显示。我也尝试了另一种使用大熊猫的方法,也正在发生同样的方法。
我只希望该表中的所有用户处理( https://practice.geeksforgeeks.org/leaderboard/ < /a>)
I want to fetch all the user handles present in this link https://practice.geeksforgeeks.org/leaderboard/
This is the code which tried,
import requests
from bs4 import BeautifulSoup
URL = 'https://practice.geeksforgeeks.org/leaderboard/'
def getdata(url):
r = requests.get(url)
return r.text
htmldata = getdata(URL)
soup = BeautifulSoup(htmldata, 'html.parser')
table= soup.find_all('table',{"id":"leaderboardTable"})
print(table[0].find_all('tbody')[1])
print(table[0].find_all('tbody')[1].tr)
Output:
<tbody id="overall_ranking">
</tbody>
None
The code is fetching the table but when i try to print the tr or td tags present in the table it is showing None. I tried another approach also using pandas, the same is happening.
I just want all the user handles present in this table (https://practice.geeksforgeeks.org/leaderboard/)
Any solution for this problem will be will be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
URL是动态的,美丽的套件无法呈现JavaScript,但是数据是从API生成的,这意味着网站使用API。
输出:
The url is dynamic and beautifulsoup can't render JavaScript but Data is generating from API meaning the website is using API.
Output:
您可以使用硒来获得此功能。
You can get this using Selenium.