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?
  • 相关阅读:
    Gradle 修改 Maven 仓库地址
    返回到上一页的html代码的几种写法
    Android网络传输中必用的两个加密算法:MD5 和 RSA (附java完成测试代码)
    MyBatis传入多个参数的问题
    8 个最优秀的 Android Studio 插件
    Html中隐藏a标签
    js中获取jsp中的参数
    同一个页面里的JS怎样获取jsp从别的页面获取的参数
    《Android源码设计模式解析与实战》读书笔记(一)
    HDU ACM 1068 最大独立集
  • 原文地址:https://www.cnblogs.com/Chinawolfman/p/5436494.html
Copyright © 2011-2022 走看看