python爬虫学习:初识爬虫

开始教程以前须要安装 Python ,本人所用的 Python 的版本是 Python3.4.4 ,直达下载连接:html

Python3.4.4python

Python 又是一个强制缩进的语言,因此一款好的 IDE 是必不可少的,直达下载连接:ide

Pycharmurl

安装的教程能够看下博客:code

pycharm基本设置htm

完事具有后,打开 IDE :blog

1. Create New Project

2. 设置工程目录 -> Create

3. 右键 Python File

4.简单爬虫

导入爬虫库:教程

import urllib.request

设置须要爬取的网页 url :get

url = "http://www.tybai.com"

获取所有网页并打印出来:pycharm

html_bytes = urllib.request.urlopen(url).read()
print(html_bytes)

获得的结果:

如今获得的结果仍是 byte 形式,将其转化为 UTF-8 的形式:

html = html_bytes.decode("UTF-8")

就这样,一个很简单的爬虫就那么实现了!