以下是一个简单的爬虫代码示例:

import requests
from bs4 import BeautifulSoup

url = 'https://example.com'  # 要爬取的网页链接

# 发送请求并获取网页内容
response = requests.get(url)
html = response.text

# 使用BeautifulSoup解析网页内容
soup = BeautifulSoup(html, 'html.parser')

# 找到需要提取数据的标签
data = soup.find('div', class_='data')

# 提取数据
result = data.text

# 打印结果
print(result)

在上面的代码中,我们首先使用requests库发送请求,获取网页内容。然后使用BeautifulSoup库解析网页内容,并通过指定标签和类名找到需要提取的数据。最后,我们将提取的数据打印出来。

请注意,这只是一个简单的示例,实际的爬虫代码可能会更复杂,需要处理更多的异常情况和数据解析。


原文地址: https://www.cveoy.top/t/topic/pCCH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录