From 433fec77c2173da5bf533eb4cc04025df33a884f Mon Sep 17 00:00:00 2001 From: 2509165044 <2509165044@student.edu.cn> Date: Tue, 24 Mar 2026 21:11:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4task-2-1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homework02/work.py | 9 +++++++++ homework03/hello.py | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 homework02/work.py create mode 100644 homework03/hello.py diff --git a/homework02/work.py b/homework02/work.py new file mode 100644 index 0000000..7e3bea6 --- /dev/null +++ b/homework02/work.py @@ -0,0 +1,9 @@ +import requests +url = 'https://example.com' +params ={'key':'value')# 查询参数#发送GET 请求并带上查询参数 +response = requests.get (url, params=params)#检查请求是否成功 +if response.status code ==200: + html content = response.text + print("请求成功,获取到HTML内容") +else: + print(f"请求失败,状态码:{response.status code)") \ No newline at end of file diff --git a/homework03/hello.py b/homework03/hello.py new file mode 100644 index 0000000..49bbfd6 --- /dev/null +++ b/homework03/hello.py @@ -0,0 +1,19 @@ +import requests +url ='https://example.com‘ +params = {'key': 'value'} +response = requests.get(url,params) +if response.status_code == 200: + html_content = response.text + print("请求成功,获取到HTML内容") +else: + print(f"请求失败,状态码:{response.status_code}") + from bs4 import BeautifulSoup + soup = BeautifulSoup(htm1_content, 'lxml' ) + title = soup.find('titl').string + print("页面标题:",title) + link = 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