有没有可能通过谷歌搜索一家公司,并让它返回公司的总部地址?假设我想搜索谷歌总部,我会进入谷歌总部,1600 Amphitheatre Parkway会返回。有没有人知道有什么库或api可以帮我解决这个问题,甚至是一大堆有地址的公司?
发布于 2019-01-18 06:44:48
可能有一个应用程序接口就有这样的信息,但是在谷歌上搜索“获取公司总部的物理地址”,会出现一个可以用作查询点的网站Corporate Office Headquarters.com,并使用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当然,还有许多其他可能的解决方案。
https://stackoverflow.com/questions/54244812
复制相似问题