简单爬取网页源码

import urllib.request

url = 'http://www.baidu.com/'
response = urllib.request.urlopen(url)
data = response.read()
str_data = data.decode('utf_8')
# print(str_data)
with open('baidu.html','w',encoding='utf_8') as  f:
    f.write(str_data)

 

posted @ 2018-11-08 16:48  徐李帅  阅读(2187)  评论(0编辑  收藏  举报