xiuhu121 2022-03-08 01:12 采纳率: 75%
浏览 1044
已结题

AttributeError: 'str' object has no attribute 'content'如何解决

    for web in web_list:
            for j in range(2,9):
                pic_web = 'https://www.jj20.com/mx/dalu/nan/baijingting/2386'+ str(i) +'_' +str(j) +'.html'
                response = requests.get(pic_web,headers=headers)
                html = response.text
                picture = re.findall('<img id="bigImg" src="(.*?)" alt=".*?">', html)
                picture = 'https:' + ''.join(picture)
                print(picture)
                file_name = picture.split('/')[-1]
                print(file_name)
                with open(r'E:\pycharm\第一个库\爬虫\白敬亭'+ '/' + file_name,'wb') as f:
                    f.write(picture.content)

一直显示AttributeError: 'str' object has no attribute 'content'

  • 写回答

1条回答 默认 最新

  • 关注
    
        for web in web_list:
            
            for j in range(2,9):
                pic_web = 'https://www.jj20.com/mx/dalu/nan/baijingting/2386'+ str(i) +'_' +str(j) +'.html'
                response = requests.get(pic_web,headers=headers)
                html = response.text
                picture = re.findall('<img id="bigImg" src="(.*?)" alt=".*?">', html)
                picture = 'https:' + ''.join(picture)
                print(picture)
                file_name = picture.split('/')[-1]
                print(file_name)
                
                picture = requests.get(picture,headers=headers)
                
                with open(r'E:\pycharm\第一个库\爬虫\白敬亭'+ '/' + file_name,'wb') as f:
                    f.write(picture.content)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月25日
  • 已采纳回答 4月17日
  • 创建了问题 3月8日

悬赏问题

  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导