You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
889 B

import requests
import lxml
from bs4 import BeautifulSoup
for i in range(1,6):
url="http://sports.people.com.cn/GB/31928/412458/index"+str(i)+".html"
headers={
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0"
}
r=requests.get(url,headers=headers)
r.encoding="GBK"
mysoup = BeautifulSoup(r.text,"lxml")
result = mysoup.select("ul.ph_list li")
for i in result:
j=i.text
print(j)
with open("qwj.txt", "a",encoding="utf-8") as f:
f.write(j + "\n")
result2 = mysoup.select("ul.list_16 li")
for i in result2:
k=i.text
with open("qwj.txt", "a",encoding="utf-8") as f:
f.write(k + "\n")