码迷,mamicode.com
首页 > 编程语言 > 详细

011 Python 爬虫库安装简单使用

时间:2017-07-27 09:35:31      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:nbsp   beautiful   lib   strong   html_   基础知识   爬虫   font   enc   

# Python 爬虫基础知识
  ● Python 爬虫基础知识
    安装爬虫库
      beautifulsoup4
        pip install beautifulsoup4

      lxml HTML 解析器
        pip install html5lib

      html5lib
        pip install html5lib

  ● 使用库
    设置 encoding=‘utf-8‘ 编码

 1 # -*- coding: UTF-8 -*-
 2 from bs4 import BeautifulSoup
 3 import lxml
 4 html_file = open(text.html,encoding=utf-8)
 5 
 6 soup = BeautifulSoup(html_file, "lxml")
 7 
 8 for item in soup.find_all(span):
 9     print(item.attrs)
10 
11 html_file.close()
12     

 

011 Python 爬虫库安装简单使用

标签:nbsp   beautiful   lib   strong   html_   基础知识   爬虫   font   enc   

原文地址:http://www.cnblogs.com/sdk123/p/7242949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!