Python urllib爬取百度首页

官网下载安装python
在VS code里面安装python插件 https://www.cnblogs.com/bloglkl/archive/2016/08/23/5797805.html

  • cmd进入python输入
/*
没报错则证明urllib安装成功
*/
from urllib.request  import urlopen
  • 直接在cmd输入
pip install beautifulsoup4//安装beautifulsoup4
  • cmd进入python输入
/*
没报错验证beautifulsoup4安装
*/
from bs4 import BeautifuSoup
  • 爬取百度首页
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import io  
import sys
from urllib import request
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') #改变标准输出的默认编码  
resp = request.urlopen("http://www.baidu.com/")
print (resp.read().decode("utf-8"))

posted @ 2017-11-14 22:48  白茶微甘  阅读(998)  评论(0编辑  收藏  举报