删除所有&LT; A&GT;标签 [英] Remove all <a> tags
本文介绍了删除所有&LT; A&GT;标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刮出一个容器,其中包括网址,例如:
&LT; A HREF =URL&gt;文字&LT; / A&GT;
我需要的所有被删除,只有在文本留...
进口urllib2的,SYS
从BS4进口BeautifulSoup网站=http://mysite.com
页= urllib2.urlopen(网站)
汤= BeautifulSoup(页)
这可能吗?
解决方案
汤= BeautifulSoup(页)
锚= soup.findAll('A')
在锚锚:
anchor.replaceWithChildren()
I scraped one container which includes urls for example:
<a href="url">text</a>
I need all to be removed and only the text remain...
import urllib2, sys
from bs4 import BeautifulSoup
site = "http://mysite.com"
page = urllib2.urlopen(site)
soup = BeautifulSoup(page)
Is it possible?
解决方案
soup = BeautifulSoup(page)
anchors = soup.findAll('a')
for anchor in anchors:
anchor.replaceWithChildren()
这篇关于删除所有&LT; A&GT;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文