python - 如何使用 beautifulsoup 抓取雅虎收入日历

标签 python html web-scraping beautifulsoup

我如何抓取雅虎收入日历以提取日期?

这是针对 python 3 的。

from bs4 import BeautifulSoup as soup
import urllib

url = 'https://finance.yahoo.com/calendar/earnings?day=2019-06-13&symbol=ibm'

response = urllib.request.urlopen(url)
html = response.read()

page_soup = soup(html,'lxml')
table = page_soup.find('p')
print(table)

输出为“无”

最佳答案

Beautiful Soup 有一些查找函数可以用来检查 DOM,请引用 documentation

from bs4 import BeautifulSoup as soup
import urllib.request

url = 'https://finance.yahoo.com/calendar/earnings?day=2019-06-13&symbol=ibm'

response = urllib.request.urlopen(url)
html = response.read()

page_soup = soup(html,'lxml')
table = page_soup.find_all('td')
Dates = []
for something in table:
    try:
        if something['aria-label'] == "Earnings Date":
            Dates.append(something.text)
    except:
        print('')

print(Dates)

关于python - 如何使用 beautifulsoup 抓取雅虎收入日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56589945/

相关文章:

python - pytest 将所有输出捕获到标准输出

python - 如何将传输语法uid添加到数据集的filemeta

jquery - 在 jquery 中滑动返回

python - 使用Selenium解决无限滚动问题

python - scrapy提取图片的url

python - 如何不等待线程在 Python 中完成

java - 删除 jsoup 中选定 id 元素的除第一个 div 之外的所有 div

html - 使用动态 ERB Id 创建单独的 div

perl - 使用Perl抓取网站

python - Docker 开发工作流程