import requests from lxml import etree

请求头

headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' }

请求链接

url = 'https://m.okooo.com/match/change.php?mid=1194233&pid=24&Type=odds'

发送请求

response = requests.get(url, headers=headers)

修改编码

response.encoding = 'gbk'

解析返回值

html = etree.HTML(response.text) companies = html.xpath('//td[@class="b_cen"]/a/text()') links = html.xpath('//td[@class="b_cen"]/a/@href')

打印结果

for i in range(len(companies)): print(companies[i], links[i]

写一段python代码 请求时带请求头请求httpsmokooocommatchchangephpmid=1194233&pid=24&Type=odds将页面编码改为gbk用xpath解析返回值中的公司名称和链接地址将解析的结果打印

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

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