文章概述
本文将详细介绍如何使用Python编写一个简单的爬虫来抓取高清美女图片。我们将利用requests
库来发送HTTP请求,使用BeautifulSoup
库来解析HTML文档,从而提取出图片的URL并将其下载到本地。
技术栈
- Python: 编程语言
- requests: HTTP客户端库
- BeautifulSoup: HTML/XML解析库
环境准备
确保安装了以下Python库:
requests
beautifulsoup4
可通过pip安装:
pip install requests beautifulsoup4
代码详解
1. 导入库
import requests
from bs4 import BeautifulSoup
2. 爬取图片
for i in range(1, 10, 1):
if i == 1:
r = requests.get('https://pic.netbian.com/4kmeinv/index.html')
else:
r = requests.get(f'https://pic.netbian.com/4kmeinv/index_{i}.html')
r.encoding = 'gbk'
html = r.