小弟是python新手 使用visual studio code以下是我的程式碥
'''
import os,time,requests,imghdr,random
from bs4 import BeautifulSoup as bs
url='https://www.google.com/search?q=%E7%BE%8E%E5%A5%B3&rlz=1C2CAFB_enTW617TW617'
headers={'user-agent': 'Mozilla/5.0'}
photolimit=5
response=requests.get(url,headers)
sp=bs(response.content,'html.parser')
items=sp.find_all('img')
folder_name='./photo/'
if (os.path.exists(folder_name)==False):
os.mkdir(folder_name)
for index,item in enumerate(items,1):
if( index < photolimit):
html=requests.get(url,item.get('src'))
img_name=folder_name+str(index)+'.jpeg'
print(html,img_name)
with open(img_name,'wb')as file:
file.write(html.content)
file.flush()
file.close()
print('第{}張已下載......'.format(index))
time.sleep(random.uniform(1,3))
print('完成~')
'''
實在不知該如何下tag