我本意是想获得这段中文的,但不管怎么改代码,获得的值都是一堆乱码,decode和encode之类的都试了,还是不行诶。有没有人能看看呀
import requests
from bs4 import BeautifulSoup
# -------------------------------------------------------------历届中国女子排球联赛获奖名单-----------------------------------------------------------------------------------
#UA伪装
headers={"user-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) A" "ppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
}
#1.指定爬虫网页网址
url="http://www.volleychina.org/hv/2023-01-19/doc-imyaterk5587468.shtml"
# 2.对URL发起请求
requests.get(url=url,headers=headers)
# 3.获取响应数据
response = requests.get(url=url,headers=headers)
page_txt = response.text
# page_txt.encoding='utf_8'
# 4数据解析
#通过BeautifulSoup解析数据
#① 实例化BeautifulSoup对象,将页面数据加载至对象,Fe_Re_soup为女性获奖对象
Fe_Re_soup=BeautifulSoup(page_txt,'lxml')
#② 解析url标签属性等
#将div<detail-context>标签下所有的p标签提取
p_list=Fe_Re_soup.select('.detail-context>p')
#提取所有p标签下span标签里的内容,FeRe为女性获奖对象
for i in p_list:
print(i)