From 1c3999d30b946d5102622098bbe705a5a23ba941 Mon Sep 17 00:00:00 2001 From: 2509165014 <2509165014@student.edu.cn> Date: Tue, 24 Mar 2026 11:30:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- m.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 m.py diff --git a/m.py b/m.py new file mode 100644 index 0000000..84d3872 --- /dev/null +++ b/m.py @@ -0,0 +1,26 @@ +import requests +from bs4 import BeautifulSoup +headers = { + 'User-Agent':'Mozilla/5.0(Windows NT 10.0;win64; x64)AppleWekit/537.36(KHRML,like Gecko) Cheome/120.0.0.0 Safari/537.36' +} +url = 'https://www.douban.com/doulist/3936288/' + +response = requests.get(url,headers=headers) +if response.status_code ==200: + html_content = response.text + print("请求成功,获取到HTML内容") + soup = BeautifulSoup(html_content,'html.parser') + title = soup.find('title').string + print("页面标题:",title) + links = soup.find_all('a') +for link in links: + href = link.get('href') + if href: + print("链接地址:",href) + book_items = soup.select('div.doulist-item') + for item in book_items: + book_title = item.select_one('div.title a').get_text(strip=True) + book_author =item.select_one('div.subject-cast').get_text(strip=True) + print(f"书名:{book_title}|作者:{book_author}") +else: + print(f"请求失败,状态码:{response.status_code}") \ No newline at end of file