From 50664a027d28e88b1667c8d2a1c395dcd1b8dca6 Mon Sep 17 00:00:00 2001 From: 2509165014 <2509165014@student.edu.cn> Date: Thu, 19 Mar 2026 16:12:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A=E4=BA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mz.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 mz.py diff --git a/mz.py b/mz.py new file mode 100644 index 0000000..91e18f0 --- /dev/null +++ b/mz.py @@ -0,0 +1,19 @@ +import requests +url = 'https://baidu.com' +params = {'key': 'value'} +response = requests.get(url, params=params) +if response.status_code == 200: + html_content = response.text + print("请求成功,获取到HTML内容") +else: + print(f"请求失败,状态码:{response.status_code}") +from bs4 import BeautifulSoup +soup = BeautifulSoup(html_content,'lxml') +title = soup.find('title').string +print("页面标题:",title) +links = soup.find_all('a') +for link in links: + print("链接地址:",link.get('href')) +div_elements = soup.select('div.class_name') +for div in div_elements: + print("div内容:",div.text) \ No newline at end of file