【发布时间】:2020-03-19 22:22:29
【问题描述】:
这里有新的编码器。我正在尝试从这里返回此网站的所有每股收益数据:https://www.nasdaq.com/market-activity/stocks/csco/revenue-eps
我只是尝试返回“March”开始缓慢,并使用以下代码:
from bs4 import BeautifulSoup
from requests import get
url = "https://www.nasdaq.com/market-activity/stocks/csco/revenue-eps"
response = get(url)
soup = BeautifulSoup(response.text, 'html.parser')
month = soup.find("th", {"class": "revenue-eps__cell revenue-eps__cell--rowheading"})
print(month.text)
当我运行它时,没有错误,但没有返回任何内容。
当我尝试运行相同的代码但改用 print(month) 时,我从如下所示的元素返回 HTML:th class="revenue-eps__cell revenue-eps__cell--rowheading" scope="row"> /th>
我注意到在返回的 HTML 中,文本不在 th 内。这是为什么?我做错了什么还是我要抓取的网站?
【问题讨论】:
-
如果您在禁用 JS 的情况下访问该页面,则不会填充该表,所以我猜这就是您的解析器看到它的方式。我的下一个建议是尝试查看进行了哪些 Ajax 调用或加载了哪些脚本来加载您正在查找的内容 - 您可能必须直接调用这些来获取数据,而不是查看生成的 HTML。
标签: python web-scraping data-science