【问题标题】:Removing <a href="#" tags python删除 <a href="#" 标签 python
【发布时间】:2013-03-14 02:30:04
【问题描述】:
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

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

任何人请......

【问题讨论】:

    标签: python html python-2.7 tags beautifulsoup


    【解决方案1】:

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

    for a in soup.find_all('a', href=lambda value: value.startswith('#')):
        a.extract()
    

    【讨论】:

      猜你喜欢
      • 2014-07-20
      • 2017-04-21
      • 2023-02-02
      • 2012-02-13
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      相关资源
      最近更新 更多