Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >'str' object cannot be interpreted as an integer?

'str' object cannot be interpreted as an integer?

提问于 2023-09-26 07:08:49
回答 0关注 0查看 279

import urllib.request import re url="https://cn.chinadaily.com.cn/" count = 0 def download(src): global count try: resp =urllib.request.urlopen(src) data = resp.read() p = src.rfind("/") fileName=src[p+1:] fobj = open("download\\"+fileName,"wb") fobj.write(data) fobj.close() print("downloaded",fileName) count = count+1 except Exception as err: print(err) def getHtml(): html = "" try: resp = urllib.request.urlopen(url) data = resp.read() html = data.decode() except Exception as err: print(err) return html try: html = getHtml().lower() reg = r"<img.+src\s*=\s*" m = re.search(reg,html) while m: a = m.end() s = html[a:] m = re.search(r">",s) if m: b = m.start() html = s[m.end():] s = s[:b] m.re.search(r"[\',\"][a-z,0-9,\.,-,_,/]+(.jpg|.png|.jpeg)[\',\"]",s) if m: src =s[1:m.end()-1] src = urllib.request.urljion(url,src) print(src) download(src) m = re.search(reg,html) print("total",count,"images") except Exception as err: print(err)

'str' object cannot be interpreted as an integer

回答

成为首答用户。去 写回答
相关文章
解决ValueError: cannot convert float NaN to integer
当我们在使用Python进行数值计算时,有时会遇到类似于​​ValueError: cannot convert float NaN to integer​​的错误。这个错误通常是由于我们试图将一个NaN(Not a Number)转换为整数类型引起的。在本篇文章中,我们将讨论这个错误的原因以及如何解决它。
大盘鸡拌面
2023/10/22
2.5K0
【最全BUG修复宝典】肝!你遇到的BUG解决方案全在这了!
5、解决 “NameError: name 'xrange' is not definedw” 错误提示
灰小猿
2021/04/19
1.4K0
【最全BUG修复宝典】肝!你遇到的BUG解决方案全在这了!
全网最值得收藏的Python常见报错及其解决方案,再也不用担心遇到BUG了!
5、解决 “NameError: name 'xrange' is not definedw” 错误提示
灰小猿
2022/05/05
1.7K0
全网最值得收藏的Python常见报错及其解决方案,再也不用担心遇到BUG了!
PHP“Cannot use object of type stdClass as array”
 php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误
Java架构师必看
2021/03/22
1K0
44.python bytes函数
python bytes对于刚接触python的小伙伴来讲,可能还是有点陌生!bytes是字节序列,值得注意的是它有取值范围:0 <= bytes <= 255;
猿说编程[Python和C]
2020/03/12
1.3K0
源码浅谈(二):java中的 Integer.parseInt(String str)方法
一、parseInt方法 ,可以看到默认又调用了parseInt(s,10) ,  第二个参数为基数,默认10 ,当然也可以自己设置 
听着music睡
2018/12/06
1.8K0
内置函数--bin() oct() int() hex()
Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.
用户7798898
2020/09/27
1.4K0
TypeError: cannot unpack non-iterable NoneType object
解决方法:报错的原因是函数返回值得数量不一致,查看函数返回值数量和调用函数时接收返回值的数量是不是一致,修改一致即可
狼啸风云
2020/09/17
5.3K0
Python报错:TypeError: the JSON object must be str, bytes or bytearray, not ‘dict‘
当我尝试运行以下代码,来练习使用json.loads()和json.dumps()函数时,系统给我报出了这个错误。
JavaEdge
2021/02/23
3.1K0
成功解决AttributeError: ‘str‘ object has no attribute ‘decode‘「建议收藏」
成功解决AttributeError: ‘str’ object has no attribute ‘decode’
全栈程序员站长
2022/09/16
3.6K0
成功解决AttributeError: ‘str‘ object has no attribute ‘decode‘「建议收藏」
启动 celery worker 报错:AttributeError: 'str' object has no attribute 'items'
错误日志 (joyoo) yinzhuoqundeMacBook-Pro:joyoo yinzhuoqun$ python manage.py celery worker --loglevel=info raven.contrib.django.client.DjangoClient: 2019-12-15 02:07:00,997 /Users/yinzhuoqun/.pyenv/joyoo/lib/python3.6/site-packages/raven/base.py [line:213] INF
卓越笔记
2023/02/18
5500
TypeError: a bytes-like object is required, not ‘str‘,如何解决?
在Python编程中,当我们在处理文件或网络传输等场景时,有时可能会遇到以下错误信息:"TypeError: a bytes-like object is required, not 'str'"。这个错误通常表示我们传递了一个字符串对象而不是字节对象,导致了类型不匹配。如下所示,我们对字段进行base64编码时,出现了报错:
霍格沃兹测试开发Muller老师
2023/09/07
8580
解决java.lang.Integer cannot be cast to java.lang.String
今天做项目得时候,发现平常Obj转Int方法用不了 错误原因是类型转换! 说Integer 类型不能转成String类型。
Erwin
2019/12/31
12.1K0
Uncaught TypeError: Cannot assign to read only property 'exports' of object
查了资料 “在webpack打包的时候,可以在js文件中混用require和export。但是不能混用import 以及module.exports ” 但是项目并没有混用 import 与 module.exports
切图仔
2022/09/08
8570
Python 运行时遇到的这些错误
对于刚入门的Python新手,在学习过程中运行代码是或多或少会遇到一些错误,刚开始可能看起来比较费劲。随着代码量的积累,熟能生巧当遇到一些运行时错误时能够很快的定位问题原题。下面整理了在Python运行中常见的错误,希望能够帮助到大家。
小小科
2020/07/15
1.1K0
出错提示AttributeError: 'str' object has no attribute 'decode'解决方法
出现上面的问题找到:Python37\lib\site-packages\django\db\backends\mysql\operations.py"。
誉新源科技
2021/10/23
1.2K1
出错提示AttributeError: 'str' object has no attribute 'decode'解决方法
dlerror: libcudart.so.10.0: cannot open shared object file
我用的是实验室的服务器,服务器安装了cuda10.1,而根据报错,程序在寻找cuda10.0的库。解决方法是可以用anaconda安装cuda10.0:
平凡的学生族
2019/11/13
4.8K0
dlerror: libcudart.so.10.0: cannot open shared object file ...
我用的是实验室的服务器,服务器安装了cuda10.1,而根据报错,程序在寻找cuda10.0的库。解决方法是可以用anaconda安装cuda10.0:
狼啸风云
2022/05/09
3120
PHP Fatal error:  Cannot use ‘Object‘ as class name as it is reserved 转
为什么80%的码农都做不了架构师?>>> 这个错误是yii2框架的错误了。也就是说不能使用Object作为类名。 解决方法 1、composer install 2、composer global
双面人
2019/05/21
3.1K0
点击加载更多

相似问题

购买一个月的服务器,没有使用代金券可以退款吗?

1498

关于ftp的问题?

1326

关于日志的问题?

1182

关于授权的问题?

1220

关于购买的问题?

1236
相关问答用户
腾讯云TDP | TDP会员擅长3个领域
平安资管 | 架构师擅长4个领域
擅长3个领域
擅长5个领域
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档