我在执行该文件,发现图片可以下载下来,但是大小只有1kb,打开便是显示文件损坏
from bs4 import BeautifulSoup
import requests, time, html5lib, pdfkit, os
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'
}
def get_info(url):
res = requests.get(url,headers=headers)
soup = BeautifulSoup(res.content,'html5lib')
content = soup.find(class_="winstyle45572")
c = content.find_all("img")
for img in c:
im = requests.get('http://www.hnuahe.edu.cn/'+img['src'])
filename = os.path.split(img['src'])[1]
with open('学校/image/'+filename, 'wb') as f:
f.write(im.content)
if __name__ == "__main__":
urls = ['http://www.hnuahe.edu.cn/info/1033/{}.htm'.format(str(i)) for i in range(1700, 1720)]
for url in urls:
get_info(url)
time.sleep(0.5)
其中还有一些莫名的错误,希望可以解答一下。