Reputation: 71
if we search website of the company in google we get following result. i need to get company info and founded year. and no of employee how can i get. is there any API availabe?. can you help me on this. thanks
Upvotes: 3
Views: 3856
Reputation: 74
Run following query in wikidata sparql endpoint
SELECT DISTINCT
?wdindustryLabel
?wdcompanyName
?wdcountryLabel
(SAMPLE(?wdemployee) AS ?wdemployee)
(SAMPLE(?wdfounded) AS ?wdfounded)
(SAMPLE(?wdofficial_website) AS ?wdofficial_website)
WHERE {
?wdcompany wdt:P31 ?type;
rdfs:label ?wdcompanyName.
OPTIONAL {
?wdcompany wdt:P452 ?wdindustry;
wdt:P1128 ?wdemployee;
wdt:P571 ?wdfounded;
wdt:P17 ?wdcountry;
wdt:P856 ?wdofficial_website.
}
FILTER(LANGMATCHES(LANG(?wdcompanyName), "EN"))
VALUES ?type {
wd:Q6881511
wd:Q43229
}
VALUES ?wdcompanyName {
"Apple Inc."@en
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?wdcompanyName ?wdindustryLabel ?wdcountryLabel
ORDER BY (?wdcompanyName)
or use following code:
# pip install sparqlwrapper
# https://rdflib.github.io/sparqlwrapper/
import sys
from SPARQLWrapper import SPARQLWrapper, JSON
endpoint_url = "https://query.wikidata.org/sparql"
query = """SELECT DISTINCT ?wdindustryLabel ?wdcompanyName ?wdcountryLabel (SAMPLE(?wdemployee) AS ?wdemployee) (SAMPLE(?wdfounded) AS ?wdfounded) (SAMPLE(?wdofficial_website) AS ?wdofficial_website) WHERE {
?wdcompany wdt:P31 ?type;
rdfs:label ?wdcompanyName.
OPTIONAL {
?wdcompany wdt:P452 ?wdindustry;
wdt:P1128 ?wdemployee;
wdt:P571 ?wdfounded;
wdt:P17 ?wdcountry;
wdt:P856 ?wdofficial_website.
}
FILTER(LANGMATCHES(LANG(?wdcompanyName), "EN"))
VALUES ?type {
wd:Q6881511
wd:Q43229
}
VALUES ?wdcompanyName {
'Apple Inc.'@en
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?wdcompanyName ?wdindustryLabel ?wdcountryLabel
Order By ?wdcompanyName"""
def get_results(endpoint_url, query):
user_agent = "WDQS-example Python/%s.%s" % (sys.version_info[0], sys.version_info[1])
# TODO adjust user agent; see https://w.wiki/CX6
sparql = SPARQLWrapper(endpoint_url, agent=user_agent)
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
return sparql.query().convert()
results = get_results(endpoint_url, query)
for result in results["results"]["bindings"]:
print(result)
Upvotes: 2
Reputation: 866
You are looking for the Google knowledge graph API. The info on the box to the right is pulled from the Google Knowledge Graph for the top result.
You can get the information you need for an Organization
entity:
An organization such as a school, NGO, corporation, club, etc.
Example properties of an Organization
include legalName
, logo
, foundingDate
For example, here is a simple query I used for Facebook:
https://kgsearch.googleapis.com/v1/entities:search?query=Facebook&key=<YOUR_API_KEY_HERE>&indent=True
And here is the result I got in return:
{
"@type": "EntitySearchResult",
"result": {
"@id": "kg:/m/0hmyfsv",
"name": "Facebook, Inc.",
"@type": [
"Corporation",
"Organization",
"Thing"
],
"description": "Social network company",
"image": {
"contentUrl": "http://t3.gstatic.com/images?q=tbn:ANd9GcTjO7_7_DBuI3EpMBdVTACYT2WDkwKGrBic0JYSGtIt1c_0oMK9",
"url": "https://commons.wikimedia.org/wiki/File:F_icon.svg"
},
"url": "https://www.facebook.com/"
},
"resultScore": 32.638672
}
BTW, for some reason, Facebook was the second on the list of results after Youtube
Update
Looks like, at the moment, the API does not provide a way to control which properties to be returned in the results, and not all properties are included in the response by default. There is a question here about how to get that done
From the API reference, the accepted request paramaters are:
query
(e.g. query=Facebook
)ids
(e.g. ids=/m/0hmyfsv
)languages
(e.g. languages=en
)types
(e.g. types=Corporation
)indent
(e.g. indent=true
)limit
(e.g. limit=2
)And the response parameters are: @id
, name
,@type
, description
, image
detailedDescription
(if available), and resultScore
The information you are looking for are actually available in the Wikipedia page included in the URL provided as part of the detailedDescription
property, so you may want to consider using the Wikidata API instead
Upvotes: 8