text = '中华'
print(type(text))#<class 'str'>
text1 = text.encode('gbk')
print(type(text1))#<class 'bytes'>
print(text1)#b'\xd6\xd0\xbb\xaa'
text2 = text1.decode('gbk')
print(type(text2))#<class 'str'>
print(text2)#中华

text4= text.encode('utf-8')
print(type(text4))#<class 'bytes'>
print(text4)#b'\xe4\xb8\xad\xe5\x8d\x8e'
text5 = text4.decode('utf-8')
print(type(text5))#<class 'str'>
print(text5)#中华

import requests

url="http://www.baidu.com"
response = requests.get(url)
content = response.text.encode('iso-8859-1').decode('utf-8')
#把网页源代码解码成Unicode编码,然后用utf-8编码
print(content)

from selenium import webdriver # 导入webdriver模块

chrome_obj = webdriver.Chrome() # 打开Google浏览器
chrome_obj.get("https://www.baidu.com") # 打开 网址
print(chrome_obj.title)

from selenium import webdriver # 导入webdriver模块

chrome_obj = webdriver.Chrome() # 打开Google浏览器

chrome_obj.get(r"C:\desktop\text.html") # 打开本地 html页面

吴裕雄 实战PYTHON编程(5)的更多相关文章

  1. 吴裕雄 实战PYTHON编程(10)

    import cv2 cv2.namedWindow("frame")cap = cv2.VideoCapture(0)while(cap.isOpened()): ret, im ...

  2. 吴裕雄 实战PYTHON编程(9)

    import cv2 cv2.namedWindow("ShowImage1")cv2.namedWindow("ShowImage2")image1 = cv ...

  3. 吴裕雄 实战PYTHON编程(8)

    import pandas as pd df = pd.DataFrame( {"林大明":[65,92,78,83,70], "陈聪明":[90,72,76, ...

  4. 吴裕雄 实战PYTHON编程(7)

    import os from win32com import client word = client.gencache.EnsureDispatch('Word.Application')word. ...

  5. 吴裕雄 实战PYTHON编程(6)

    import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['Simhei']plt.rcParams['axes.unicode ...

  6. 吴裕雄 实战PYTHON编程(4)

    import hashlib md5 = hashlib.md5()md5.update(b'Test String')print(md5.hexdigest()) import hashlib md ...

  7. 吴裕雄 实战python编程(3)

    import requests from bs4 import BeautifulSoup url = 'http://www.baidu.com'html = requests.get(url)sp ...

  8. 吴裕雄 实战python编程(2)

    from urllib.parse import urlparse url = 'http://www.pm25x.com/city/beijing.htm'o = urlparse(url)prin ...

  9. 吴裕雄 实战python编程(1)

    import sqlite3 conn = sqlite3.connect('E:\\test.sqlite') # 建立数据库联接cursor = conn.cursor() # 建立 cursor ...

随机推荐

  1. OpenWrt在没有Luci时刷机

    scp上传bin文件到root文件夹下. sysupgrade openwrt-ar71xx-generic-dragino2-squashfs-sysupgrade.bin 等待重启

  2. windows环境下把Python代码打包成独立执行的exe可执行文件

    有时候因为出差,突然急需处理一批数据.虽然写好的脚本存储在云端随用随取,然而编译的环境还需要重新搭建,模块也需要重新装载,从头到尾这么一遍下来,也是要花费可观的时间成本的. 有没有什么办法,可以让.p ...

  3. spring boot学习(2) SpringBoot 项目属性配置

    第一节:项目内置属性 application.properties配置整个项目的,相当于以前的web.xml: 注意到上一节的访问HelloWorld时,项目路径也没有加:直接是http://loca ...

  4. maven学习(5)-Maven 聚合与继承特性

    接着上面的项目, 继承和聚合为了统一管理: 聚合: 有些项目中有很多小模块,可以合并到一起,将多个子项目可以统一管理,可以对user-dao,user-service进行统一管理(maven clea ...

  5. fiddler工具能干啥

    1.通过模拟弱网进行测试(试了木有效果) http://www.cnblogs.com/LanTianYou/p/7095174.html (试了貌似没反应) http://caibaojian.co ...

  6. [转]Java.APK 反编译

    本文转自:http://blog.csdn.net/vipzjyno1/article/details/21039349/ (注:反编译不是让各位开发者去对一个应用破解搞重装什么的,主要目的是为了促进 ...

  7. override的实现原理

    转载 http://blog.csdn.net/fan2012huan/article/details/51007517 基于基类的调用和基于接口的调用,从性能上来讲,基于基类的调用性能更高 .因为i ...

  8. MySQL 特殊参数

    ###开发规范 开发规范:关键字大写,库名字小写,要有字符集 CREATE DATABSE oldboy CHARSET utf8;    ###建议采用第一种 CREATE DATABSE oldb ...

  9. EC20 MODULE serial com log in passwd

    ec20 module would print debug info via debug uart, and you can log in by user root, the passwd is qu ...

  10. SQL SERVER回滚恢复误操作的数据

    在生产数据库做CURD操作时,可能会有执行某条语句误操作的情况发生,针对这个种情况有两点建议: 1. 在SQL SERVER上开启事务确认功能,当执行完语句后确认无误,再提交事务.(开启方法见附件图片 ...