移除<;a href="#&引用;标记python arg=urllib2.urlopen(argv[1]).read() 汤=美汤(arg) a_tags=soup.find_all('a')#因此它存储了一个包含所有标记的列表

移除<;a href="#&引用;标记python arg=urllib2.urlopen(argv[1]).read() 汤=美汤(arg) a_tags=soup.find_all('a')#因此它存储了一个包含所有标记的列表,python,html,python-2.7,tags,beautifulsoup,Python,Html,Python 2.7,Tags,Beautifulsoup,我只需要那些没有链接到同一页面的页面(href中没有符号#) 任何人请……您可以将href属性与函数匹配: arg = urllib2.urlopen(argv[1]).read() soup = BeautifulSoup(arg) a_tags = soup.find_all('a') #so this stores a list with all the <a href="" /a> tags for a in soup.find_all('a', href=lambda v

我只需要那些没有链接到同一页面的页面(href中没有符号#)


任何人请……

您可以将
href
属性与函数匹配:

arg = urllib2.urlopen(argv[1]).read()
soup = BeautifulSoup(arg)
a_tags = soup.find_all('a') #so this stores a list with all the <a href="" /a> tags
for a in soup.find_all('a', href=lambda value: value.startswith('#')):
    a.extract()