beautiful soup 重新解析返回的一组 table 行 beautiful soup
beautiful soup re-parse a returned set of table rows beautiful soup
我正在尝试解析第二组数据。我向 gigya 状态页面发出一个获取请求,我解析出对美丽汤很重要的部分。然后我使用 html 的 return 字符串尝试用漂亮的汤解析它但是我得到一个标记错误但是 returned 内容字符串也是一个字符串所以我不确定为什么..
错误
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
行soup2 = BeautifulSoup(rows)
是不必要的; rows
此时已经是一个 BeautifulSoup.Tag
对象。你可以简单地做:
rows = rows[8]
items = rows.findAll('td')
我正在尝试解析第二组数据。我向 gigya 状态页面发出一个获取请求,我解析出对美丽汤很重要的部分。然后我使用 html 的 return 字符串尝试用漂亮的汤解析它但是我得到一个标记错误但是 returned 内容字符串也是一个字符串所以我不确定为什么..
错误
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
行soup2 = BeautifulSoup(rows)
是不必要的; rows
此时已经是一个 BeautifulSoup.Tag
对象。你可以简单地做:
rows = rows[8]
items = rows.findAll('td')