【python爬虫】—图片爬取,nikon d70
0evadmin
编程语言
7
文件名:【python爬虫】—图片爬取,nikon d70
【python爬虫】—图片爬取
图片爬取 需求分析Python实现 需求分析 从https://pic.netbian.com/4kfengjing/网站爬取图片,并保存 Python实现 获取待爬取网页 def get_htmls(pages=list(range(2, 5))):"""获取待爬取网页"""pages_list = []for page in pages:url = f"https://pic.netbian.com/4kfengjing/index_{page}.html"response = requests.get(url)response.encoding = 'gbk'pages_list.append(response.text)return pages_listget_htmls(pages=list(range(2, 5))) 获取所有图片,并下载 def get_picturs(htmls):"""获取所有图片,并下载"""for html in htmls:soup = BeautifulSoup(html, 'html.parser')pic_li = soup.find('div', id='main').find('div', class_='slist').find('ul', class_='clearfix')image_path = pic_li.find_all('img')for file in image_path:pic_name = './practice05/' + file['alt'].replace(" ",'_') + '.jpg'src = file['src']src = f"https://pic.netbian.com/{src}"response = requests.get(src)with open(pic_name, 'wb') as f:f.write(response.content)print("图片已下载并保存为:{}".format(pic_name))htmls = get_htmls(pages=list(range(2, 5)))get_picturs(htmls) 爬取结果展示
同类推荐
-

【Python 千题 —— 基础篇】列表排序,sony z1 mini
查看 -

【Python+requests+unittest+excel】实现接口自动化测试框架,第三代酷睿
查看 -

【Python3】【力扣题】338. 比特位计数,卓越亚马逊图书
查看 -

【Python3爬虫】为什么你的博客没人看呢?,网络电视怎么看春晚
查看 -

【PythonRS】基于GDAL修改栅格数据的DN值,西门子cx65
查看 -

【Python】Error:'int' object is not callable,aerial7耳机
查看 -

【Python】Numpy库近50个常用函数详解和示例,可作为工具手册使用,牵手红娘
查看 -

【Python】torch.exp()和 torch.sigmoid()函数详解和示例,戴尔m15x
查看 -

【Python】基于OpenCV人脸追踪、手势识别控制的求生之路FPS游戏操作,rs690
查看