问题描述:Python 中报错TypeError: expected string or bytes-like object

解决方法:根据报错上方的提示信息,大体猜测到可能出错的具体地方。出现该报错一般为数据类型不匹配造成的,可以通过print(type(object))来查当前的数据类型,式中object为要查询的对象。

print(type(xml_data.xpath('/html/head/script[5]/text()')))

输出结果:

<class 'list'>

因此上述xpath获取的数据可考虑采用下述方式进行使用

xml_data.xpath('/html/head/script[5]/text()')[0]

Python 报错TypeError: expected string or bytes-like object相关推荐

  1. python报错 TypeError: an integer is required

    问题描述: 在本地使用socket向NetAssist传送数据的时候,执行python文件后发现报出python 报错TypeError: an integer is required错误 代码: 1 ...

  2. python3报错 TypeError: can’t concat bytes to str 原因与解决方法

    在做项目的时候,Python3会报错如下错误: TypeError: can't concat bytes to str 意思是: 类型错误:无法将字节连接到字符串 类似的错误有: TypeError ...

  3. Python报错TypeError: 'str' object is not callable

    原文:http://blog.sina.com.cn/s/blog_71f3890901017rsh.html Python报错TypeError: 'str' object is not calla ...

  4. Python报错TypeError: ‘User‘ object is not iterable

    Python报错TypeError: 'User' object is not iterable 原因 User对象是不可迭代的,我这里是因为User并不是list,所以是不可迭代的,所以不使用迭代即 ...

  5. Python报错 TypeError: Descriptors cannot not be created directly

    Python报错TypeError: Descriptors cannot not be created directly 具体错误: TypeError: Descriptors cannot no ...

  6. Python报错TypeError: Descriptors cannot not be created directly

    Python报错TypeError: Descriptors cannot not be created directly 具体错误: TypeError: Descriptors cannot no ...

  7. python报错TypeError: must be str, not int

    python报错TypeError: must be str, not int 字符串拼接一个整型变量报错,代码如下 for i in range(1,586):res = 'test' + i 报错 ...

  8. [cx_oracle]报错:expecting string or bytes object

    目标:将dataframe直接批量插入Oracle数据库 语句: # coding=utf-8 #设置语言环境 import os os.environ['NLS_LANG'] = 'SIMPLIFI ...

  9. react native报错:Expected a component class,got[object object]

    正在写RN的视图部分,突然模拟器报错:Expected a component class,got[object object].找也找不到原因.后来才发现是自己粗心大意造成的. 错误代码: < ...

最新文章

  1. 【读书笔记】iOS-属性
  2. Python 模块之 time datetime
  3. 变频器服务器电路板维修,变频器电路板维修技巧
  4. 微软服务器延迟,经过六个多月的延迟,微软终于推出Hyper-V Server 2019
  5. install numpy for arm64
  6. 学习《Python核心编程》做一下知识点提要,方便复习(二)
  7. linux常用命令练习:wc、cut、|、tee、tail
  8. TestComplete自动化测试视频教程
  9. 计算机无纸化考试合卷答题笔记卡,中级会计职称无纸化答题技巧
  10. 如何在 Mac 上映射网络驱动器
  11. aix curl 安装_命令行下载工具(Curl)
  12. 保存为UTF-8格式的Txt文件
  13. qt button clicked(bool) always false
  14. 两张MD5值一样但实际不一样的图片
  15. 批量安装windows系统补丁包
  16. 今日学习在线编程题:弓形半径
  17. 如何将台式机的网络共享给另外一台台式机
  18. 为什么自建 UI 框架?
  19. C++贪吃蛇的简单实现版
  20. 树莓派3B——Mailbox

热门文章

  1. 解决url中特殊字符截断参数的问题
  2. Handshake failed due to invalid Upgrade header: null 解决方案
  3. 自监督学习推荐系统综述: 150篇自监督推荐系统文献概述四大类方法(含开源算法库SELFRec)...
  4. 【实践】预训练模型在华为信息流推荐中的应用与探索.pdf(附下载链接)
  5. 【报告分享】2020企业精细化运营白皮书.pdf(附下载链接)
  6. java递归mysql生成树_java递归生成树结构的数据
  7. asp系统转换php系统时间函数,window_Asp常用通用函数之生成时间的整数,'函数名:GetMyTimeNumber()' - phpStudy...
  8. java中的几个“区别”总结
  9. TensorBoard 1.15.0 at http://DESKTOP-DV74NQ2:6006/ 打开html后无法展示解决方案
  10. 该设备或资源(Web代理)未设置为接受端口“7890“上的连接解决方案