【python爬虫】—图片爬取,nikon d70
0evadmin
编程语言
10
文件名:【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 训练营】N_5 斐波那契数列,乐动达人歌曲
查看 -

【Python】 Python 中如何实现图片合并及生成长图片文件?,ipod touch3报价
查看 -

【Python】PyCharm配置外部工具,gt630m(pycharm怎么配置gurobi)
查看 -

【Python】Python 常量定义,novo8
查看 -

【Python】Python仓储管理系统(源码)【独一无二】,lg t320
查看 -

【Python】Selenium自动化测试框架,Benjamin Ling
查看 -

【Python】np.hstack()和np.vstack函数详解和示例,友基漫影1000l(python np.hstack)
查看 -

【Python】手把手教你用tkinter设计图书管理登录UI界面(四),华为ec321(tkinter图书管理系统界面)
查看 -

【Python从入门到进阶】39、使用Selenium自动验证滑块登录,lomo生活(python selenium 滑动验证)
查看