import requests
from lxml import etree
from bs4 import BeautifulSoup
url = "http://www.glutnn.cn/list.aspx?s=1&ClassID=110101&Curpage=1"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 '
'Safari/537.36 Edg/111.0.1661.62'}
response = requests.get(url=url, headers=headers)
response.encoding = 'utf-8'
html = etree.HTML(response.text)
# 保存网页→html文件
open('work.html', 'w', encoding='utf-8').write(response.text)
# 解析页面信息
soup = BeautifulSoup(open('work.html', encoding='utf-8'), features='html.parser')
# 获取所有 class_="td_list" 的 <td></td>
for title in soup.find_all('td', class_="td_list"):
# <td>标签下第一个<a>标签的文本的值
print(title.a.text)
参考文章:https://huaweicloud.csdn.net/63808503dacf622b8df8986b.html?spm=1001.2101.3001.6650.16&utm_medium=distribute.pc_relevant.none-task-blog-2defaultBlogCommendFromBaiduactivity-16-127072138-blog-123870433.235^v28^pc_relevant_recovery_v2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2defaultBlogCommendFromBaiduactivity-16-127072138-blog-123870433.235v28pc_relevant_recovery_v2&utm_relevant_index=24