Beautifulsoup爬虫步骤

需要的库:

  • requests
  • bs4
  • Beautifulsoup

    大概思路:使用requests模块向网站发送请求,转化并下载标准HTML文档,使用Beautifulsoup的函数提取网页元素。
    结合文档TAG,就能快捷的提取网页元素。

>from bs4 import BeautifulSoup
>brken_html=’<ulclass=country><li>Area<li>Populationul>’
>#parsetheHTML
>soup=BeautifulSoup(broken_html,’html.parser’)
>fixedhtml=soup.prettify()
>print fixedhtml
<html>
<body>
<ulclass=”country”〉
<li>Area</工i>
<li>Populationli>
ul>
body>
html>

你可能感兴趣的:(python笔记)