美丽的汤重新解析一套返回的表行美丽的汤

时间:2015-04-16 15:54:45

标签: python beautifulsoup html-parsing gigya

我正在尝试解析第二组数据。我向gigya状态页面提出请求,我用美丽的汤解析了重要的部分。然后我把html的返回字符串试图解析那个美丽的汤,但我得到一个标记错误但是返回的内容字符串也是一个字符串,所以我不知道为什么..

错误

Traceback (most recent call last):
  File "C:\Users\Administraor\workspace\ChronoTrack\get_gigiya.py", line 17, in <module>
    soup2 = BeautifulSoup(rows)
  File "C:\Python27\lib\site-packages\bs4\__init__.py", line 161, in __init__
    markup = markup.read()
TypeError: 'NoneType' object is not callable

import requests
import sys
from bs4 import BeautifulSoup
url = ('https://console.gigya.com/site/apiStatus/getTable.ashx')
r = requests.request('GET', url)
content = str(r.content)

soup = BeautifulSoup(content)
table = soup.findAll('table')
rows = soup.findAll('tr')

rows = rows[8]
soup2 = BeautifulSoup(rows) #this is where it fails
items = soup2.findAll('td')
print items

1 个答案:

答案 0 :(得分:2)

soup2 = BeautifulSoup(rows)是不必要的;此时rows已经是BeautifulSoup.Tag个对象。你可以这样做:

rows = rows[8]
items = rows.findAll('td')