Python 爬取百度首页 HTML 代码示例
下面是一个简单的 Python 代码示例,用于爬取百度首页的 HTML 内容:
import requests
url = 'https://www.baidu.com'
response = requests.get(url)
if response.status_code == 200:
html_content = response.text
print(html_content)
else:
print('请求失败')
该代码使用 requests 库发送一个 GET 请求,将百度首页的 HTML 内容保存在 html_content 变量中,并打印出来。
原文地址: https://www.cveoy.top/t/topic/p1Jx 著作权归作者所有。请勿转载和采集!