由于新浪财经网站的页面结构较为复杂,需要通过模拟浏览器行为来获取页面数据。这里我们使用selenium模块来模拟浏览器操作,再通过BeautifulSoup模块来解析页面内容。

以下是获取上市公司高管学历的代码:

from selenium import webdriver
from bs4 import BeautifulSoup

# 设置Chrome浏览器驱动的文件路径
driver_path = 'chromedriver.exe'

# 创建Chrome浏览器驱动
driver = webdriver.Chrome(executable_path=driver_path)

# 访问新浪财经网站上市公司高管页面
url = 'https://vip.stock.finance.sina.com.cn/corp/go.php/vCI_CorpManager/stockid/600519/menu_num/2.phtml'
driver.get(url)

# 等待页面加载完成
driver.implicitly_wait(10)

# 获取页面源代码
html = driver.page_source

# 关闭浏览器驱动
driver.quit()

# 解析页面内容
soup = BeautifulSoup(html, 'html.parser')
table = soup.find('table', class_='comInfo1')
rows = table.find_all('tr')[1:]

# 遍历表格的每一行数据,提取高管学历信息
for row in rows:
    name = row.find('td', class_='name').text.strip()
    education = row.find_all('td')[2].text.strip()
    print(name, education)

在上述代码中,我们首先创建了一个Chrome浏览器驱动,并访问了新浪财经网站上市公司高管页面。然后,我们使用BeautifulSoup模块解析页面,并找到了包含高管信息的表格。最后,我们遍历表格的每一行数据,提取高管学历信息,并输出到控制台上。

需要注意的是,由于新浪财经网站的页面结构可能随时发生变化,因此以上代码可能需要根据实际情况进行调整。


原文地址: https://www.cveoy.top/t/topic/v6W 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录