如何使用Google Python客户端库以编程方式使用Google自定义搜索API搜索引擎进行高级搜索,以便n
根据我查询的高级搜索的某些术语和参数返回第一个链接列表?
我试图检查文档(我没有找到任何例子),这个答案.但是,后者没有用,因为目前不支持AJAX API.到目前为止我试过这个:
from googleapiclient.discovery import build
import pprint
my_cse_id = "test"
def google_search(search_term, api_key, cse_id, **kwargs):
service = build("customsearch", "v1",developerKey="<My developer key>")
res = service.cse().list(q=search_term, cx=cse_id, **kwargs).execute()
return res['items']
results = google_search('dogs', my_api_key, my_cse_id, num=10)
for result in results:
pprint.pprint(result)
Run Code Online (Sandbox Code Playgroud)
还有这个:
import pprint
from googleapiclient.discovery import build
def main():
service = build("customsearch", "v1",developerKey="<My developer key>")
res = service.cse().list(q='dogs').execute()
pprint.pprint(res)
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
因此,任何关于如何使用谷歌的搜索引擎API进行高级搜索的想法?这就是我的凭据在Google控制台上的显示方式:
python google-api google-search-api python-3.x google-api-python-client
我有一个这样的词典列表:
l = [{'pet': 'cat', 'price': '39.99', 'available': 'True'},
{'pet': 'cat', 'price': '67.99', 'available': 'True'},
{'pet': 'dog', 'price': '67.00', 'available': 'False'}
,....,
{'pet': 'fish', 'price': '11.28', 'available': 'True'}]
Run Code Online (Sandbox Code Playgroud)
我怎样才能将上面的列表转换成?(*)
:
l_2 = [('cat','39.99','True'),('cat','67.99','True'),('dog','67.00','False'),....,('fish','11.28','True')]
Run Code Online (Sandbox Code Playgroud)
我尝试使用.items()
和l[1]
:
for l in new_list:
new_lis.append(l.items())
Run Code Online (Sandbox Code Playgroud)
但是,我无法将字典列表的第二个元素位置提取到元组列表中,如 (*)
我正在使用这个正则表达式匹配几种日期格式.
(?i)\b\d{1,2}[-|–|—|\s|(?:\sde\s|\sdel\s)|\d+/](?:Ene|Enero|Feb|Febrero|Mar|Marzo|Abril|Mayo|May|Jun|Junio|Jul|Julio|Ago|Agosto|Sep|Sept|Septiembre|Oct|Octubre|Nov|Noviembre|Dic|Diciembre|\d+)[-|–|—|\s|(?:\sde\s|\sdel\s)|\d+/](?:\d{4}|\d{2})\b
但是,我不知道如何添加到以前的正则表达式支持匹配格式,如下所示:
11 de Noviembre de 2013
23 de noviembre del 2011
11 de Noviembre del 2013
Run Code Online (Sandbox Code Playgroud)
正如您在上面的正则表达式中看到的那样,我尝试使用\w(\sde\s|\sdel\s)
和(?:\sde\s|\sdel\s)
.然而它不起作用.我如何匹配以前的日期案例?