Python 删除<;a>;来自beautifulsoup结果的HTML标记

Python 删除<;a>;来自beautifulsoup结果的HTML标记,python,html,web-scraping,beautifulsoup,python-requests,Python,Html,Web Scraping,Beautifulsoup,Python Requests,使用beautifulsoup,我可以使用以下代码刮取网页: import requests from bs4 import BeautifulSoup page = requests.get("http://www.acbbroker.it/soci_dettaglio.php?r=3") page soup = BeautifulSoup(page.content, 'html.parser') test = soup.find(id="paginainterna-content") t

使用beautifulsoup,我可以使用以下代码刮取网页:

import requests
from bs4 import BeautifulSoup

page = requests.get("http://www.acbbroker.it/soci_dettaglio.php?r=3")
page

soup = BeautifulSoup(page.content, 'html.parser')
test = soup.find(id="paginainterna-content")
test_items = test.find_all(class_="entry-content")
tonight = test_items[0]

names = []
for x in tonight.find_all('a', itemprop="url"):
    names.append(str(x))
print(names)
但我无法清理结果并仅获取段落中的内容(同时删除href)

下面是我的一个小快照:

 '<a href="http://www.google.com/maps/place/45.45249938964844,9.210599899291992" itemprop="url" target="_blank">A&amp;B; Insurance e Reinsurance Brokers Srl</a>', '<a href="http://www.google.com/maps/place/45.647499084472656,8.774800300598145" itemprop="url" target="_blank">A.B.A. BROKERS SRL</a>', '<a href="http://www.google.com/maps/place/45.46730041503906,9.148480415344238" itemprop="url" target="_blank">ABC SRL BROKER E CONSULENTI DI ASSI.NE</a>', '<a href="http://www.google.com/maps/place/45.47710037231445,9.269220352172852" itemprop="url" target="_blank">AEGIS INTERMEDIA SAS</a>',
“”,“”,“”,“”,
处理此类数据并获得干净结果的正确方法是什么


谢谢

如果您只需要标签中的文本,请使用
get_text()
方法

for x in tonight.find_all('a', itemprop="url"):
    names.append(x.get_text())                                                                                                                                                    
print(names)
更好地理解
列表
这是最快的

names = [x.get_text() for x in tonight.find_all('a', itemprop='url')]

我不知道你想要什么样的输出,但是,你通过改变这个得到的文本

names.append(str(x.get_text()))

您应该使用单个容器的所需输出更新您的问题,以使其更清晰。