完成作y
This commit is contained in:
8
yzz.py
8
yzz.py
@@ -1,8 +0,0 @@
|
||||
import requests
|
||||
url = 'http://example.com'
|
||||
params = {'key':'value'}
|
||||
response = requests.get(url, params=params)
|
||||
if response.status_code == 200:
|
||||
print("请求成功,获取到HTML内容")
|
||||
else:
|
||||
print(f"请求失败,状态码:{response.status_code}")
|
||||
21
余子尊 11
Normal file
21
余子尊 11
Normal file
@@ -0,0 +1,21 @@
|
||||
import requests
|
||||
ur1 = 'https://example.com'
|
||||
params = {'key': 'value'}
|
||||
response = requests.get(ur1,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,'lsml')
|
||||
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)
|
||||
Reference in New Issue
Block a user