初学者python web scrape问题

时间:2016-01-14 07:24:51

标签: python web-scraping beautifulsoup

我有以下HTML代码:

<div class="panel panel-default box">
<div class="panel-heading">
<h2 class="panel-title">December 2015</h2>
</div>
<div class="panel-body">
<ul>
    <li>December 30, 2015 - <a href="link">Report</a></li>
    <li>December 23, 2015 - <a href="link">Report</a></li>
    <li>December 16, 2015 - <a href="link">Report</a></li>
    <li>December 9, 2015 - <a href="link">Report</a></li>
    <li>December 2, 2015 - <a href="link">Report</a></li>
</ul>
</div>
</div>

我编写了以下python代码来删除上面的一些内容。

from bs4 import BeautifulSoup
import lxml
import requests
import textwrap
import csv

BASE_URL = "link"
response = requests.get(BASE_URL)
html = response.content

#each monthly list starts with <div class="panel-body">
soup = BeautifulSoup(html,"lxml")

list_of_links = soup.findAll('div', attrbs={'class': "panel-body"})

print list_of_links

由于某些原因,Python不断返回空的“list_of_links”

有谁知道我做错了什么?

感谢。

1 个答案:

答案 0 :(得分:1)

你似乎有一个错字:

attrbs={'class': "panel-body"})

应该是attrs不是 attrbs