首先,你需要安装Python的requests和BeautifulSoup库。然后,你可以使用requests库来发送HTTP请求,并用BeautifulSoup库来解析HTML文档。
import requests
from bs4 import BeautifulSoup
requests.get('http://www.91hfdm.com') 这行代码会向 ‘http://www.91hfdm.com’ 发送一个GET请求,然后返回响应。
response.text 这行代码会返回响应的文本内容。
soup = BeautifulSoup(response.text, 'lxml')
BeautifulSoup(response.text, 'lxml') 这行代码会将响应的文本内容解析为BeautifulSoup对象。
soup.find_all('a') 这行代码会找到所有的<a>标签。
for link in soup.find_all('a'):
print(link.get('href'))
for link in soup.find_all('a') 这行代码会遍历所有的<a>标签。
print(link.get('href')) 这行代码会打印出每个<a>标签的href属性。
# 使用代理
proxy_host = 'jshk.com.cn'
proxy = {
'http': 'http://' + proxy_host + ':' + str(proxy_port),
'https': 'http://' + proxy_host + ':' + str(proxy_port)
}
response = requests.get('http://www.91hfdm.com', proxies=proxy)
proxy = {'http': 'http://' + proxy_host + ':' + str(proxy_port), 'https': 'http://' + proxy_host + ':' + str(proxy_port)} 这行代码会创建一个字典,表示HTTP代理。
response = requests.get('http://www.91hfdm.com', proxies=proxy) 这行代码会使用HTTP代理发送GET请求。


















