我正在尝试使用beautifulsoup.name获得美丽的汤返回文本。但它只是给了我[文件]一个美丽的汤对象。关于如何使用Beautiful Soup在XML文件中返回文本的任何建议?
import BeautifulSoup as bsoup
f = open(file)
soup = bsoup(f)
f.close()
f = soup.name
This code will return [document]
But I'm looking to for a function in beautiful soup to return:
<name>car</name>
答案 0 :(得分:0)
根据Beautiful Soup 4的Beautiful Soup Documentation,
我看到了
你想要
import BeautifulSoup as bsoup
f = open(file)
soup = BeautifulSoup(f)
f.close()`
print(soup.find('name'))
打印<name>car</name>
或print (soup.find('name').name)
以打印car
。