【发布时间】:2019-08-10 16:52:22
【问题描述】:
我创建了一个函数,它返回给定特定公司名称的 url 列表。我想知道通过这个 url 列表搜索并查找有关该公司是否为另一家公司所有的信息。
示例:“Marketo”公司被 Adobe 收购。
我想返回某家公司是否被收购以及被谁收购。
这是我目前所拥有的:
import requests
from googlesearch import search
from bs4 import BeautifulSoup as BS
def get_url(company_name):
url_list = []
for url in search(company_name, stop=10):
url_list.append(url)
return url_list
test1 = get_url('Marketo')
print(test1[7])
r = requests.get(test1[7])
html = r.text
soup = BS(html, 'lxml')
stuff = soup.find_all('a')
print(stuff)
我是网络抓取的新手,我不知道如何真正搜索每个 URL(假设我可以)并找到我想要的信息。
test1的值如下表:
['https://www.marketo.com/', 'https://www.marketo.com/software/marketing-automation/', 'https://blog.marketo.com/', 'https://www.marketo.com/software/', 'https://www.marketo.com/company/', 'https://www.marketo.com/solutions/pricing/', 'https://www.marketo.com/solutions/', 'https://en.wikipedia.org/wiki/Marketo', 'https://www.linkedin.com/company/marketo', 'https://www.cmswire.com/digital-marketing/what-is-marketo-a-marketers-guide/']
【问题讨论】:
-
你能给我们
test1列表的值吗? -
您在维基百科链接中寻找的信息并不容易找到。右边的信息框中没有这个信息,所以你必须使用一些语言处理在文本上找到它
-
我认为您的要求是不可能的 - 要从网页上抓取信息,您必须知道在该网页上的哪个位置可以找到它。您无法保证这些信息甚至出现在特定公司的网站上——更不用说每个网站上的“统一”位置了。您可能最好寻找一个 API 来获取此类信息 - 例如,我看到对于英国公司,您可以使用 this。不知道其他国家有没有类似的。
-
提交程序化搜索查询是违反 Google 的Webmaster Guidelines 和terms of service 的。对 Google 运行此代码可能会导致 Google 显示来自您 IP 地址的搜索的验证码。
标签: python web-scraping beautifulsoup google-search