Python3错误:google图像搜寻器中预期的字符串或类似字节的对象

时间:2018-09-30 08:01:49

标签: web-crawler python-3.6 python-2.6

###print images
for i , (img , Type) in enumerate(ActualImages):
    try:
        req = urllib.request.Request(img,headers={'User-Agent' : header})

        raw_img = urllib.request.urlopen(req).read().decode("utf-8")

        cntr = len([i for i in os.listdir(DIR) if image_type in i]) + 1
        print (cntr)
        if len(Type)==0:
            f = open(os.path.join(DIR , image_type + "_"+ str(cntr)+".jpg"), 'wb')
        else :
            f = open(os.path.join(DIR , image_type + "_"+ str(cntr)+"."+Type), 'wb')
        f.write(raw_img)
        f.close()
    except Exception as e:
        print ("could not load : "+img)
        print (e)

这是我的代码的一部分,该代码已从python2.7脚本转换为python3,所以我可能不知道有什么区别。有人知道它的作用吗?

这是错误回溯: enter image description here

0 个答案:

没有答案