提交task-2-1作业
This commit is contained in:
9
homework02/work.py
Normal file
9
homework02/work.py
Normal file
@@ -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)")
|
||||||
19
homework03/hello.py
Normal file
19
homework03/hello.py
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user