写一个蜘蛛抓取
以下是一个简单的 Python 蜘蛛抓取代码,用于从网站中收集信息:
import requests
from bs4 import BeautifulSoup
# 要抓取的网站 URL
url = "http://example.com/"
# 发送 GET 请求
response = requests.get(url)
# 将 HTML 响应解析为 BeautifulSoup 对象
soup = BeautifulSoup(response.text, 'html.parser')
# 找到所有的链接
links = soup.find_all('a')
# 打印所有的链接
for link in links:
print(link.get('href'))
这个蜘蛛会访问指定的网站,找到所有的链接,然后打印出来。您可以根据需要修改代码来收集其他类型的信息。请注意,抓取网站的过程可能会受到法律和伦理限制,请确保您有权访问和使用这些信息。
原文地址: https://www.cveoy.top/t/topic/eoVX 著作权归作者所有。请勿转载和采集!