为什么我只通过wikidata python包获得一个关键字结果?

问题描述 投票:1回答:1

我想得到文本中包含关键字“tweet about”的所有实体,这是我的python代码:`import wikidata import requests

API_ENDPOINT="https://www.wikidata.org/w/api.php"
query="tweet about"
params={
    'action':'wbsearchentities',
    'format':'json',
    'language':'en',
    'search':query
}
r=requests.get(API_ENDPOINT,params=params)
print(r.json())

并且打印内容是:

[{'repository': '', 'id': 'Q58571598', 'concepturi': 'http://www.wikidata.org/entity/Q58571598', 'title': 'Q58571598', 'pageid': 58483717, 'url': '//www.wikidata.org/wiki/Q58571598', 'label': 'Tweet about Skin or a Digital Homage to Skin', 'match': {'type': 'label', 'language': 'en', 'text': 'Tweet about Skin or a Digital Homage to Skin'}}]

但是当我在wikidata中搜索时,有很多结果:

enter image description here

enter image description here

谁能帮我?非常感谢你!

wikidata wikidata-api
1个回答
0
投票

看起来像两个搜索系统use a different API

你可能应该玩这样的东西:

import requests

API_ENDPOINT = "https://www.wikidata.org/w/api.php"
query = "tweet about"
params = {
    'action': 'query',
    'list':'search',
    'format': 'json',
    'srsearch': query,
    'srprop' : 'titlesnippet|snippet',
    'srlimit':100
}

r = requests.get(API_ENDPOINT, params=params)
print(r.json())

Documentation

© www.soinside.com 2019 - 2024. All rights reserved.