繁体   English   中英

如何从 Python 中抓取日期部分

[英]How to scrape the date part from Python

我正在尝试抓取这个网站: https : //www.reuters.com/companies/tsla.oq/financials/income-statement-quarterly

我正在使用 Python,除了日期部分之外的所有内容都可以被抓取......即我无法抓取“30-Jun-20”。 我试过

from requests import get
from bs4 import BeautifulSoup
url = 'https://www.reuters.com/companies/tsla.oq/financials/income-statement-quarterly'
response = get(url)
html_soup = BeautifulSoup(response.text, 'html.parser')
table = html_soup.find_all('div', class_ = 'tables-container')
table[0].thead.tr.find('time', class_ = 'TextLabel__text-label___3oCVw TextLabel__black___2FN-Z TextLabel__medium___t9PWg').text

但它显示空白...你能帮帮我吗? 那将不胜感激。

您无法使用动态添加数据的请求(使用 javascript)从网站获取数据。 您需要使用硒来实现这一点。

参考这个代码:

from selenium import webdriver
from bs4 import BeautifulSoup
DRIVER_PATH="Your selenium chrome driver path"
url = 'https://www.reuters.com/companies/tsla.oq/financials/income-statement-quarterly'
driver = webdriver.Chrome(executable_path=DRIVER_PATH)
driver.get(url)
html_soup = BeautifulSoup(driver.page_source, 'html.parser')
table = html_soup.find_all('div', class_ = 'tables-container')
driver.quit()
print(table[0].thead.tr.find('time', class_ = 'TextLabel__text-label___3oCVw TextLabel__black___2FN-Z TextLabel__medium___t9PWg').text)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM