帮我写一个python爬取网站信息收集程序
好的,以下是一个简单的Python爬虫程序:
import requests
from bs4 import BeautifulSoup
# 定义要爬取的网站URL
url = "https://www.example.com"
# 发起请求
response = requests.get(url)
# 解析HTML页面
soup = BeautifulSoup(response.content, "html.parser")
# 提取页面信息
title = soup.title.string
links = [link.get("href") for link in soup.find_all("a")]
# 输出结果
print("网站标题:", title)
print("页面链接:", links)
以上程序使用requests库发起HTTP请求,然后使用BeautifulSoup库解析HTML页面。最后提取页面信息并输出结果。你可以根据实际需要修改程序中的URL和提取规则。
原文地址: https://www.cveoy.top/t/topic/eEkH 著作权归作者所有。请勿转载和采集!