import requests from bs4 import BeautifulSoup

获取百度首页

url = 'https://www.baidu.com/' response = requests.get(url)

解析HTML

soup = BeautifulSoup(response.text, 'html.parser')

获取所有链接

links = [] for link in soup.find_all('a'): href = link.get('href') if href and href.startswith('http'): links.append(href)

输出链接

for link in links: print(link)

完成- -个完整的python程序开放满分40分。类型爬虫基本要求 3、自行编写不得在网上拷贝 4必须百度首页获取一个网站 5用新手能看懂的代码

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

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