使用python提取httpswwwcourtgovcnzixungengduo24_3html网页中的标题及链接
以下是使用Python代码实现提取https://www.court.gov.cn/zixun/gengduo/24_3.html网页中的标题及链接的方法:
import requests
from bs4 import BeautifulSoup
url = 'https://www.court.gov.cn/zixun/gengduo/24_3.html'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
news_list = soup.find(class_='xwzx_list').find_all('li')
for news in news_list:
title = news.find('a').get('title')
link = news.find('a').get('href')
print(title, link)
运行以上代码,即可在控制台中输出所有新闻标题及链接。其中,使用requests库发送请求获取网页内容,使用BeautifulSoup库解析网页内容,通过查找HTML标签提取新闻标题及链接
原文地址: https://www.cveoy.top/t/topic/gg8p 著作权归作者所有。请勿转载和采集!