Python爬取三亚学院社会学院所有p标签文本 - 代码详解
import requests from bs4 import BeautifulSoup
请求url
url = 'http://soc.sanya.edu.cn/'
发送请求
response = requests.get(url)
解析HTML页面
soup = BeautifulSoup(response.text, 'html.parser')
找到所有p标签
p_tags = soup.find_all('p')
遍历所有p标签
for p in p_tags: # 输出p标签中的文本 print(p.text.strip()) # strip()函数用于去除字符串前后的空格
原文地址: https://www.cveoy.top/t/topic/nhP9 著作权归作者所有。请勿转载和采集!