【问题标题】:beginner python web scrape issue初学者python网络抓取问题
【发布时间】:2016-01-14 07:24:51
【问题描述】:

我有以下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”

有谁知道我做错了什么?

谢谢。

【问题讨论】:

    标签: python web-scraping beautifulsoup


    【解决方案1】:

    你这里好像有错字:

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

    应该是attrs不是 attrbs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-20
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多