查询公司名称,return总部物理地址使用python?

Query company name, return headquarters physical address using python?

是否可以通过google搜索公司并return公司总部地址?假设我想搜索 Google HQ,我会输入 google 总部,1600 Amphitheatre Parkway 会输入 return。有谁知道任何图书馆或 api 能够帮助我解决这个问题,甚至是一大堆有地址的公司?

可能 API 有此信息,但是 Google 搜索 "get company headquarters physical address" 找到了一个网站 Corporate Office Headquarters.com that could be used as a query point and parsed with BeautifulSoup:

import requests
from bs4 import BeautifulSoup

company = 'google'

url = 'http://www.corporate-office-headquarters.com/search-static?term={c}&page=1&rows=200'.format(c=company)

r = requests.get(url)

soup = BeautifulSoup(r.text, 'html.parser')

endpoint = soup.find('a', href=True, attrs={'class': "match-result-anchor"})['href']

url = 'http://www.corporate-office-headquarters.com/{ep}'.format(ep=endpoint)

r = requests.get(url)

soup = BeautifulSoup(r.text, 'html.parser')

HQ_address = soup.find_all('dd')[2]   # locate the Address Tag

print(HQ_address.text) 

应该显示:

1600 Amphitheatre Parkway

当然还有很多其他可能的解决方案。