python写条爬虫
以下是一个简单的Python爬虫示例:
import requests
from bs4 import BeautifulSoup
url = 'https://www.example.com'
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
links = soup.find_all('a')
for link in links:
print(link.get('href'))
else:
print('Error:', response.status_code)
这个爬虫使用requests模块获取网页内容,然后使用BeautifulSoup模块解析HTML。它查找页面中的所有链接,并打印它们的URL。请注意,这个示例不包括错误处理或其他高级功能,但它可以作为入门级爬虫的起点。
原文地址: https://www.cveoy.top/t/topic/baA6 著作权归作者所有。请勿转载和采集!