【发布时间】:2020-07-14 10:54:30
【问题描述】:
我正在尝试使用 Python 中的 googlesearch api 来获取多个查询的前 10 名结果,但遇到了两个问题:
- 使用 'country' 参数(例如 country='us' 等)更改国家/地区似乎对结果没有任何影响。在多个国家/地区尝试过。
- 我想包含广告结果,但找不到任何方法。
如果有人知道如何使用 googlesearch 或任何其他免费 API 来做到这一点,那就太好了。
谢谢!
# coding: utf-8
from googlesearch import search
from urlparse import urlparse
import csv
import datetime
keywords = [
"best website builder"
]
countries = [
"us",
"il"
]
filename = 'google_results.csv'
with open(filename, 'w') as f:
writer = csv.writer(f, delimiter=',')
for country in countries:
for keyword in keywords:
print "Showing results for: '" + keyword + "'"
writer.writerow([])
writer.writerow([keyword])
for url in search(keyword, lang='en', stop=10, country=country):
print(urlparse(url).netloc)
print(url)
writer.writerow([urlparse(url).netloc, url])
【问题讨论】:
标签: python python-3.x google-search google-search-api