爬虫
        
  # 一段简单的爬虫代码
下面是一段简单的 Python 爬虫代码,可以爬取一个网页的 HTML 内容:
import requests
url = 'https://www.example.com'
response = requests.get(url)
if response.status_code == 200:
    html_content = response.text
    print(html_content)
else:
    print("Failed to retrieve the content")
 1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
该代码使用了 requests 库来向给定的 URL 发起请求,然后获取响应的 HTML 内容。如果响应的状态码是 200,则说明请求成功,打印出 HTML 内容;否则说明请求失败,打印失败信息。
上次更新: 2023/02/11, 10:03:57