无法使用Beautifulsoup从网站读取表格 - python

我正在尝试使用以下代码阅读网站的内容。

import requests
from bs4 import BeautifulSoup

url  = "https://chartink.com/screener/test-121377" 
r    = requests.get(url)
data = r.text
soup = BeautifulSoup(data,"html.parser")

print(soup)

结果,当我在浏览器中手动执行“检查”元素时,无法看到该表。

无法使用Beautifulsoup从网站读取表格 - python

使用硒可能是一种解决方案。但是,如果可能,我正在寻找其他替代解决方案。

关于如何从HTML的基础脚本中读取数据的任何想法吗?

参考方案

在这种情况下,您应该尝试新发布的requests_html库,该库具有处理动态生成的项目的功能。如果您遵守我刚才所说的,这就是您的脚本的外观:

import requests_html

session = requests_html.HTMLSession()
r = session.get('https://chartink.com/screener/test-121377')
r.html.render(sleep=5)
items = r.html.find("table#DataTables_Table_0",first=True)
for item in items.find("tr"):
    data = [td.text for td in item.find("th,td")]
    print(data)

输出:

['Sr.', 'Stock Name', 'Symbol', 'Links', '% Chg', 'Price', 'Volume']
['1', 'Axis Bank Limited', 'AXISBANK', 'P&F | F.A', '-1.33%', '522.6', '12,146,623']
['2', 'Reliance Industries Limited', 'RELIANCE', 'P&F | F.A', '-1.29%', '900.05', '14,087,564']
['3', 'Tata Steel Limited', 'TATASTEEL', 'P&F | F.A', '-1.89%', '600.2', '11,739,582']

Python:BeautifulSoup-根据名称属性获取属性值 - python

我想根据属性名称打印属性值,例如<META NAME="City" content="Austin"> 我想做这样的事情soup = BeautifulSoup(f) //f is some HTML containing the above meta tag for meta_tag in soup(&#…

Requests.get无法与&字符一起使用 - python

我正在使用以下网址进行request.get调用:https://api.datasource.com/apps/ios/ranking?countries=NL&categories=Overall > Kids > 5 & Under&device=ios&ranks=1000 我收到"categor…

在返回'Response'(Python)中传递多个参数 - python

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…

Python-使用请求时发布请求失败 - python

使用外壳程序时,我可以通过运行以下命令成功创建新用户curl --user administrator:pasword "Content-Type: application/json" https://localhost:8080/midpoint/ws/rest/users -d @user.json但是,当我尝试使用请求在python…

Python exchangelib在子文件夹中读取邮件 - python

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…