由于没有关闭标签,Beautifulsoup放在错误的地方

时间:2017-09-06 20:26:03

标签: python-3.x web-scraping beautifulsoup

我对数据抓取非常陌生并试图从<li>标记中提取数据,但是beautifulsoup一直将所有结束</li>标记放在代码的最后,所以这是不可能的索引。查看页面源时,我注意到Web设计人员没有使用结束标记。我猜这就是问题发生的原因。

我想抓的网站:http://www.catholic-hierarchy.org/country/bus2.html

到目前为止

代码:

from bs4 import BeautifulSoup
import requests

page = requests.get("http://www.catholic-hierarchy.org/country/bus2.html")
soup = BeautifulSoup(page.content, 'html.parser')

#since there are many ul tags we will find the cild of the tag we want and then go to its parent
ul = soup.find('br').parent.find_all('li')[2]
print (ul)

我想知道是否有人可以提供解决方案或一些有关解决此问题的方法的见解。

谢谢!

0 个答案:

没有答案