美文网首页
爬虫学习_BeautifulSoup安装使用

爬虫学习_BeautifulSoup安装使用

作者: leogoforit | 来源:发表于2020-03-15 12:19 被阅读0次

    BeautifulSoup是python爬虫中常用的库,它通过定位HTML标签来格式化和组织复杂的网络信息,用简单易用的Python对象为我们展现XML结构信息。

    这篇文章是我在学习图书《Python 网络数据采集》的笔记。


    《Python 网络数据采集》

    1、安装BeautifulSoup

    现在python3都用的是BeautifulSoup4,由于我使用的是anaconda,所以这些包就不用单独安装了。单独安装的方法为:
    pip install BeautifulSoup4

    2、爬取一个简单网页的标题

    from urllib.request import urlopen
    from bs4 import BeautifulSoup
    html = urlopen("http://www.pythonscraping.com/pages/page1.html")
    bsObj = BeautifulSoup(html.read())
    print(bsObj.h1)
    

    输出以下结果:
    <h1>An Interesting Title</h1>

    相关文章

      网友评论

          本文标题:爬虫学习_BeautifulSoup安装使用

          本文链接:https://www.haomeiwen.com/subject/sesqdhtx.html