From 692c930175a1272aac882c11769276f4ab21ef85 Mon Sep 17 00:00:00 2001 From: p7bsalm5w <1050939162@qq.com> Date: Tue, 18 Jun 2024 14:26:30 +0800 Subject: [PATCH] ADD file via upload --- 2.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 2.py diff --git a/2.py b/2.py new file mode 100644 index 0000000..e2e8ce4 --- /dev/null +++ b/2.py @@ -0,0 +1,24 @@ +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")