From 5984c819618c4cce5d06252f46a718edbe99347a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=85=A7=E8=8C=B9?= <2509165015@student.example.com> Date: Thu, 19 Mar 2026 15:58:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 15张慧茹.ini | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 15张慧茹.ini diff --git a/15张慧茹.ini b/15张慧茹.ini new file mode 100644 index 0000000..47cb882 --- /dev/null +++ b/15张慧茹.ini @@ -0,0 +1,30 @@ +import requests +from bs4 import BeautifulSoup as bs +headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" +} + +url = 'https://www.baidu.com' +params = {'key':'value'} + +try: + response = requests.get(url, params=params, headers=headers, timeout=5) + response.raise_for_status() + print("状态码:", response.status_code) + print('-'*20) + + html_content = response.text + soup = bs(html_content, 'lxml') + title = soup.find('title').string + print("页面标题:", title) + print('='*20) + links = soup.find_all('a') + for link in links: + href = link.get('href') + if href: + print("链接:", href) + print('='*20) +except requests.exceptions.RequestException as e: + print(f"请求错误: {e}") +except Exception as e: + print(f"解析错误: {e}") \ No newline at end of file