我正在尝试在给定网页中找到下一个 ul 元素。
我首先将我的回复插入到 Beautiful Soup 中,如下所示:
soup = BeautifulSoup(response.context)
打印出 response.context 给出以下内容
print(response.context)
<!DOCTYPE html>
<html>
<head>
<title> | FollowUp</title>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<link href='/static/css/bootstrap.min.css' rel='stylesheet' media='screen'>
</head>
<body>
<div class='navbar'>
<div class='navbar-inner'>
<a class='brand' href='/'>TellMe.cat</a>
<ul class='nav'>
<li><a href='list'>My Stories</a></li>
<li><a href='add'>Add Story</a></li>
<li><a href='respond'>Add Update</a></li>
</ul>
<form class='navbar-form pull-right' action='process_logout' method='post'>
<input type='hidden' name='csrfmiddlewaretoken' value='RxquwEsaS5Bn1MsKOIJP8uLtRZ9yDusH' />
Hello add!
<button class='btn btn-small'>Logout</button>
</form>
</div>
</div>
<div class='container'>
<ul id='items'>
<ul>
<li><a href='http://www.example.org'>http://www.example.org</a></li>
<ul>
<p>There have been no follow ups.</p>
</ul>
</ul>
</ul>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src='/static/js/bootstrap.min.js'></script>
</body>
</html>
我正在尝试获取名为“项目”的 ul。我这样做:
items = soup.find(id='items')
这给了我正确的 ul 及其所有孩子。然而调用
items.find_next('ul')
给出的错误
TypeError: 'NoneType' object is not callable
尽管这似乎是根据 Beautiful Soup 文档应该如何称呼它:https ://beautiful-soup-4.readthedocs.org/en/latest/#find-all-next-and-find-next
我做错了什么?