标签:google-custom-search google-api-python-client python python-3-x
devKey = 'FAUX123456789'
customSearchEngineId = 'FAUX123456789'
searchTermArray = ['happy pets valencia CA',
'pet doctor z tuscon AZ',
'best friends veterinary hospital crossville TN',
'pet pal animal shelter st petersburg FL']
termsToExclude = ['happy','pet','vet']
numberOfResults = 1
for eachSearchTerm in searchTermArray:
service = build("customsearch", "v1", developerKey=devKey)
results = service.cse().list(q=eachSearchTerm, cx=customSearchEngineId, num=numberOfResults, excludeTerms=termsToExclude)
results = results['items']
print(results)
根据google custom search API documentation,excludeTerms采用字符串值.正如您所看到的,我尝试插入一个字符串数组,但它并不常用.我实际上是独立测试每个术语,每次都会产生不同的结果. (请原谅互联网,因为我无法发布实际链接)
下面是每个测试的结果:
> termsToExclude =”
happypetsveterinarydotcom /
petdoctorxdotcom /
bestfriendsvetdotorg /
petpalanimalshelterdotcom /
termsToExclude = [‘happy’,’pet’,’vet’]
happypetsveterinarydotcom /
ollinghillspetclinicdotcom /
bestfriendsvetdotorg /
petpalanimalshelterdotcom /
termsToExclude =’happy’
krisersdotcom /位置/巴伦西亚/
valenciaanimalhospitaldotcom / reviews.html
bestfriendsvetdotorg /
petpalanimalshelterdotcom / adopt.php
termsToExclude =’pet’
teambusbydotcom /房地产新闻/家和设计/ 60 – 设计 – 快乐宠物 – 从 – 环游世界60张照片
www.zmansiondotcom /
www.bestfriendequinedotcom /
disneyworld.disney.godotcom /娱乐/魔法王国/字符会见高飞 – 唐纳德/
termsToExclude =’vet’
happypetsveterinarydotcom /医疗记录/我 – 宠物医疗记录/
www.staystudio6dotcom / EN / motels.az.tucson.6002.html
langeanimalhospitaldotcom /乔什 – 朋友/
petpalanimalshelterdotcom /事件/ purrfect-姿势瑜伽/
现在..
谷歌vague user-friendly documentation声明如下:
excludeTerms string:标识不应出现在搜索结果中的任何文档中的单词或短语.
我不确定“搜索结果中的任何文档”究竟是什么意思,但我通过这个过程发现的是,当使用单个字符串时,它似乎排除了带有字符串值的URL,但是当一个字符串数组时使用它,它似乎没有相同的行为.有谁能解释一下?或者请解释是否有正确的方法来插入此关键字excludeTerms参数中的一系列术语?
我想澄清一下,我想要完成的是能够插入一个字符串数组,以便我的结果将专门排除包含termsToExlude中的术语的URL,以便我可以在结果中获得更理想的URL.另外,请记住,当我使用单个字符串时,会产生所需的结果,而数组似乎不会以相同的方式工作.
感谢您的任何信息!
解决方法:
excludeTerms是一个扁平字符串,因此不确定在数组中传递的行为.
尝试一下
termsToExclude = 'happy pet vet'
标签:google-custom-search,google-api-python-client,python,python-3-x 来源: https://codeday.me/bug/20190910/1799498.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。