2013-04-28 189 views
0

我在查找表中的a標籤,我想排除第一個a垃圾實例。請任何解決方案?不包括第一場比賽,BeautifulSoup

標籤的語法是相同的,所以我不能使用像id=False等任何東西。我想我限制介紹一個範圍莫名其妙。

回答

1

我可能只是使用find_all(),然後切片結果:

all_a_tags = soup.find_all('a') 
for tag in all_a_tags[1:]: 
    process(tag) 

我不記得是否find_all()返回一個列表或一個迭代器,所以如果你得到一個錯誤消息,當您嘗試切在find_all()結果,緊裹list()周圍:

all_a_tags = list(soup.find_all('a')) 
for tag in all_a_tags[1:]: 
    process(tag) 

希望這有助於。

+0

感謝rmunn。列表()包裝並不需要順便說一句。 – nutship 2013-04-28 07:01:48