我如何抓取雅虎收入日历以提取日期?
这是针对 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/