我想使用beautifulsoup提取所需的单词。对于我的应用程序,我使用arxivapi来获取搜索相关论文的总数。对于我的查询,我使用了electron进行搜索。API返回的总搜索结果约为144055。我想提取这个总数
import urllib.request as ur
from bs4 import BeautifulSoup
url = 'http://export.arxiv.org/api/query?search_query=all:electron' # arxiv:api
s = ur.urlopen(url)
sl = s.read()
soup = BeautifulSoup(sl, 'html.parser')
print(soup.prettify('latin-1'))
desire_word=soup.find('opensearch:totalresults')
print(desire_word)
我打印欲望字。但我是全文的
<opensearch:totalresults xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">144055</opensearch:totalresults>
我怎样才能得到总数(144055)
没有足够的声誉来评论,但是当你遇到不确定返回什么的情况时需要注意:
这样你就能看到了
1)单词不是字符串,而是元素
2)desire_word有一个名为“text”和“听起来很有用,让我试试
desire_word.text
”的属性你很接近
相关问题 更多 >
编程相关推荐