我正在尝试解析第二组数据。我向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
答案 0 :(得分:2)
行soup2 = BeautifulSoup(rows)
是不必要的;此时rows
已经是BeautifulSoup.Tag
个对象。你可以这样做:
rows = rows[8]
items = rows.findAll('td')