zoukankan      html  css  js  c++  java
  • <Web Scraping with Python>:Chapter 1 & 2

    <Web Scraping with Python>

    Chapter 1 & 2: Your First Web Scraper & Advanced HTML Parsing

    • BeautifulSoup 

    Key:

        P5:

    • urlib or urlib2?

     If you’ve used the urllib2 library in Python 2.x, you might have noticed that things have changed somewhat between urllib2 and urllib. In Python 3.x, urllib2 was renamed urllib and was split into several submodules: urllib.request, urllib.parse, and url lib.error. Although function names mostly remain the same, you might want to note which functions have moved to submodules when using the new urllib. 

    在学习这本书之前,使用过此package(我一开始学习Python就用的是3.x,Mac自带Python2.x),当时出错了,上Stackoverflow找到了答案,现在这本书提到了这点,重新回顾一下。如果你用过 Python 2.x 里的 urllib2 库,可能会发现 urllib2 与 urllib 有些不同。在 Python 3.x 里,urllib2 改名为 urllib,被分成一些子模块:urllib.requesturllib.parse 和 urllib.error。尽管函数名称大多和原来一样,但是在用新的 urllib 库时需要注意哪些函数被移动到子模块里了。

      

        P15:

    • When to get_text() and When to Preserve Tags?

    .get_text() strips all tags from the document you are working with and returns a string containing the text only. For example, if you are working with a large block of text that contains many hyperlinks, paragraphs, and other tags, all those will be stripped away and you’ll be left with a tagless block of text.

    Keep in mind that it’s much easier to find what you’re looking for in a BeautifulSoup object than in a block of text. Call‐ ing .get_text() should always be the last thing you do, immedi‐ ately before you print, store, or manipulate your final data. In general, you should try to preserve the tag structure of a document as long as possible. 

        P16:

    • find() and findAll() with BeautifulSoup?
  • 相关阅读:
    搭建本地开发环境(第1篇)
    sqoop安装和使用
    hive的安装与简单使用
    HDFS shell操作
    【iOS基础学习随笔-1】-基于对象的程序设计
    【iOS面试系列-1】iOS中@property 后assign,copy,retain,weak,strong的意义与区别(必考-必须详细掌握)
    11. 盛最多水的容器
    使用优先队列完成了一个Astar搜索算法的c++实现,有时间可以完整的完成一遍
    20. 有效的括号
    剑指 Offer 59
  • 原文地址:https://www.cnblogs.com/Chinawolfman/p/5436494.html
Copyright © 2011-2022 走看看