现在的位置: 首页 > 综合 > 正文

用python3抓取中文网页

2019年08月04日 ⁄ 综合 ⁄ 共 299字 ⁄ 字号 评论关闭

http://www.oschina.net/code/snippet_241930_9550

#! /usr/bin/python3.2
import sys
import urllib.request
req = urllib.request.Request('http://www.baidu.com')
response = urllib.request.urlopen(req)
the_page = response.read()   #byte类型
type = sys.getfilesystemencoding() #转换成本地系统编码
html=the_page.decode(type)   #str类型
print(html) 

抱歉!评论已关闭.