python爬虫-图片
# 下面的要爬的网站链接和图片保存目录根据自身情况修改
注: 不同网站之间结构不同,所以需要适当的修改一下代码

import requests
import re
from bs4 import BeautifulSoup

url = 'https://umei.net/'
response = requests.get(url=url)
response.encoding = 'utf-8'
text_soup = BeautifulSoup(response.text, 'html.parser')
text_find_all = text_soup.find_all('li', attrs={'class': 'i_list list_n2'})
photo_list = []
for i in text_find_all:
    links = i.find('a').get('href')
    old_link = links.split('/', maxsplit=1)[-1]
    new_link = url + old_link
    photo_list.append(new_link)

for i in photo_list:
    response = requests.get(url=i)
    response.encoding = 'utf-8'
    photo_soup = BeautifulSoup(response.text, 'html.parser')
    photo_links = photo_soup.find('div', attrs={'class': 'image_div'})
    photo = photo_links.find('img').get('src')
    picture_split = photo.rsplit('/', maxsplit=1)[-1]
    with open(f'../../python爬虫/other网页图片/图片/{picture_split}', mode='wb') as picture:
        picture.write(requests.get(photo).content)  # 转换成字节,写入文件
        print(f"{picture_split}下载完毕")
觉得有帮助可以投喂下博主哦~ 一分也是爱!感谢!
转载请注明文章地址及作者哦~
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇