我用python(我失去了赌注)为我的朋友制作了一个脚本,该脚本通过data-thumb_url标记下载了所有缩略图(约50张img,一个img大小为20 kB)。
>此代码能否破坏网站或对网站造成严重影响(我的意思是DDOS或类似的东西)?我使用了10、20、30张img几次,效果很好,网站也正常工作(非常受欢迎的网站,它是世界上最流行的网站之一,并不是说该网站进行爬网是非法的,但是我需要知道它是否是安全代码。
from PIL import Image
from bs4 import BeautifulSoup
import requests
import os
url = '' #(here is the url of website)
response = requests.get(url)
soup = BeautifulSoup(response.text,'html.parser')
images = soup.find_all('img')
listt = []
for i in images:
try:
listt.append(i['data-thumb_url'])
except KeyError:
pass
for i in range(len(listt)):
img = Image.open(requests.get(listt[i],stream = True).raw)
img.save("image"+str(i)+".jpg")
我知道考虑每天80-100百万的网站访问量,例如免费的扩展程序/网站/程序以从网站下载图像,这是一个有点愚蠢的问题,但是我是bs的新手,并且是Python +中的请求我很着急。