print(city.string + u'\nAQI指数:' + aqi.string+ u'\nPM2.5浓度:' + pm25.string + pm25danwei.string + u'\n空气质量:' + quality.string + space.sub("",replacechar.sub('',str(result))).encode('utf-8'))
TypeError: can only concatenate str (not "bytes") to str

==========完整代码如下:

import urllib.request
import threading
from time import ctime
import bs4    #besutifulsoup的第三版
import redef getPM25(cityname):site = 'http://www.pm25.com/city/' + cityname + '.html'html = urllib.request.urlopen(site)soup =bs4.BeautifulSoup(html)city = soup.find("span",{"class":"city_name"})  # 城市名称aqi = soup.find("a",{"class":"cbol_aqi_num"})   # AQI指数pm25 = soup.find("span",{"class":"cbol_nongdu_num_1"})   # pm25指数pm25danwei = soup.find("span",{"class":"cbol_nongdu_num_2"})   # pm25指数单位quality = soup.find("span",{"class":re.compile('cbor_gauge_level\d$')})  # 空气质量等级result = soup.find("div",{"class":'cbor_tips'})   # 空气质量描述replacechar = re.compile("<.*?>")  #为了将<>全部替换成空space = re.compile(" ")print(city.string + u'\nAQI指数:' + aqi.string+ u'\nPM2.5浓度:' + pm25.string + pm25danwei.string + u'\n空气质量:' + quality.string + space.sub("",replacechar.sub('',str(result))).encode('utf-8'))print('*'*20 + ctime() + '*'*20)def one_thread(cityname1):   # 单线程print('One_thread Start: ' + ctime() + '\n')getPM25(cityname1)def two_thread():   # 多线程print('Two_thread Start: ' + ctime() + '\n')threads = []t1 = threading.Thread(target=getPM25,args=('beijing',))threads.append(t1)t2 = threading.Thread(target=getPM25,args=('shenyang',))threads.append(t2)for t in threads:# t.setDaemon(True)t.start()if __name__ == '__main__':print("*"*20+"welcome to 京东放养的爬虫"+"*"*20)while True:cityname1 = input("请输入想要查看的城市名称:(例如:beijing)")if cityname1 == 'quit':breakone_thread(cityname1)

python3出现TypeError: can only concatenate str (not bytes) to str的错误,大一刚上手python的学习,望大神解决。感激不尽相关推荐

  1. TypeError: can only concatenate str (not “bytes“) to str

    执行python脚本时提示"TypeError: can only concatenate str (not "bytes") to str"错误,如图示所示: ...

  2. python从入门到大神---4、python3文件操作最最最最简单实例

    python从入门到大神---4.python3文件操作最最最最简单实例 一.总结 一句话总结: python文件操作真的很简单,直接在代码中调用文件操作的函数比如open().read(),无需引包 ...

  3. Python3遇到TypeError:cannot use a string pattern on a bytes-like object错误

    今天写一个爬取股票网站的爬虫,遇到了 TypeError:cannot use a string pattern on a bytes-like object 错误,这个问题查询了一下,说使用     ...

  4. python 解决bytes和str之间 出现 TypeError的问题

    解决TypeError: can only concatenate str (not "bytes") to str 错误提示: pic_content = pic_content ...

  5. python3字符编码str_聊聊Python 3 的字符串:str 和 bytes 的区别

    Python2的字符串有两种:str 和 unicode,Python3的字符串也有两种:str 和 bytes.Python2 的 str 相当于 Python3 的bytes,而unicode相当 ...

  6. Python高能小技巧:了解bytes与str的区别

    导读:Python有两种类型可以表示字符序列:一种是bytes,另一种是str. 作者:布雷特·斯拉特金(Brett Slatkin) 来源:大数据DT(ID:hzdashuju) bytes实例包含 ...

  7. Python 了解 bytes 与 str 的区别

    Python 有两种类型可以表示字符序列 bytes:实例包含的是原始数据,即 8 位的无符号值(通常按照 ASCII 编码标准来显示) str:实例包含的是 Unicode 码点(code poin ...

  8. TypeError: Can‘t mix strings and bytes in path components

    TypeError: Can't mix strings and bytes in path components 在运行某程序时,出现以下错误: Can't mix strings and byte ...

  9. python里str什么意思_Python 3 字符串中的 STR 和 Bytes 究竟有什么区别?

    原标题:Python 3 字符串中的 STR 和 Bytes 究竟有什么区别? Python2的字符串有两种:str和Unicode,Python3的字符串也有两种:str和Bytes.Python2 ...

  10. python str与bytes之间的转换

    python str与bytes之间的转换 # bytes object b = b"example"# str object s = "example" # ...

最新文章

  1. form表单会跨域_前端跨域So Easy
  2. linux系统负载状态检查脚本
  3. Qt 控制台 使用connect连接信号和槽
  4. XAMPP的MYSQL无法启动 -This may be due to a blocked port, missing dependencies,
  5. 高性能mysql整理
  6. 科普|什么是负载均衡
  7. 一天学习一个设计模式之命令模式
  8. Spring4.x(12)--SpringEL-HelloWorld
  9. SpringBoot中的定时任务和异步任务
  10. 使用Foobar2000在PC上播放.ios音乐
  11. 详解Vue中的自定义指令
  12. 使用ODAC将SqlServer数据库同步到oracle数据库
  13. 古剑奇谭ol服务器位置,国产网游史上第一次?古剑奇谭OL将把WeGame与360服务器数据互通...
  14. Springboot整合Redis实现腾讯云发送短信验证码并实现注册功能
  15. 数据投毒攻防对抗技术-2.推荐系统中的数据投毒
  16. 锐捷(七)设备软件版本升级更新
  17. 程序员转行可以做什么?
  18. 不得不佩服下自己:关于正反双面打印的问题分析
  19. 正则表达式判断是不是手机号
  20. Excel 表格实现多列排序

热门文章

  1. 桌面上的计算机打不开怎么办,电脑桌面计算机打不开怎么办
  2. linux下制作dos启动u盘启动,在Linux系统下创建FreeDOS可启动U盘
  3. 关于VirtualBox运行出现“0x00000000指令引用的0x00000000内存。该内存不能为written”的解决方法
  4. Win7 VirtualBox运行出现“0x00000000指令引用的0x00000000内存。该内存不能为written” ,错误解决
  5. 在多树联动和动态生树的情况下给树上添加新节点
  6. php吧输出结果进行分割,[判断题] 呼叫处理程序按照一定的逻辑对呼叫进行处理,对呼叫的处理结果与局数据、用户数据的内容无关。...
  7. 极大极小搜索算法 minimax search
  8. 打印机连接计算机主机的,电脑怎样连接打印机,详细教您电脑如何连接网络打印机...
  9. 计算机酷炫桌面,电脑桌面还能这么酷炫?!打破次元壁的桌面管理软件
  10. 【毕业设计】基于树莓派的指纹识别与RFID考勤系统 - 嵌入式 单片机 物联网