手机
当前位置:查字典教程网 >脚本专栏 >python >Python ValueError: invalid literal for int() with base 10 实用解决方法
Python ValueError: invalid literal for int() with base 10 实用解决方法
摘要:今天在写爬虫程序的时候由于要翻页,做除法分页的时候出现了复制代码代码如下:totalCount='100'totalPage=int(tot...

今天在写爬虫程序的时候由于要翻页,做除法分页的时候出现了

复制代码 代码如下:

totalCount = '100' totalPage = int(totalCount)/20

ValueError: invalid literal for int() with base 10的错误

网上同样的错误有人建议用round(float(“1.0″)),但是解决不了我这个问题,round(float(“1.0″))是用于解决浮点数转换为整形数的,

而我这个则是因为原字符串转换为整形后做除法,虽然一段时间内可能不报错,但时间久了就会提示(其实就是一个warning,但是会强制终止你的程序),正确解决方法如下:

复制代码 代码如下:

去除掉字符串中的非数字字符即可。亲测可用

【Python ValueError: invalid literal for int() with base 10 实用解决方法】相关文章:

python解析html开发库pyquery使用方法

Python urllib模块urlopen()与urlretrieve()详解

python基础教程之类class定义使用方法

Python strip lstrip rstrip使用方法

pymssql ntext字段调用问题解决方法

Python BeautifulSoup中文乱码问题的2种解决方法

python sys模块sys.path使用方法示例

在python的WEB框架Flask中使用多个配置文件的解决方法

忘记ftp密码使用python ftplib库暴力破解密码的方法示例

Python实例之wxpython中Frame使用方法

精品推荐
分类导航