Python2爬虫下载的图片为什么会打不开

发布时间:2019-08-02 16:20:26

本人菜鸟一枚,奈何领导让我学习爬虫,我就简单学着写了点爬虫,但是爬下来的图片打不开或已损坏,球大神指点迷津,感谢

import requests

from bs4 import BeautifulSoup 

url='http://newcar.xcar..cn/photo/m38486/'

res=requests.get(url)

soup=BeautifulSoup(res.text,'html.parser')

ID=1

for A in soup.select('dl'):

    for B in A.select('dt'):

        for C in B.select ('img'):

            print C['src']

            D=C['src']

            jepg=open('E:\Python\PythonJDPG\\'+str(ID)+'.jpg','wb')

            jepg.write(D)

            jepg.close

            ID+=1


推荐回答

还没有选出推荐答案,请稍候访问或查看其他回答!
以上问题属网友观点,不代表本站立场,仅供参考!