Python 在Google自定义搜索API中从搜索结果中排除多个术语
根据,excludeTerms采用字符串值。如您所见,我尝试插入字符串数组,但效果不太好。实际上,我独立地测试了每一个术语,每次都产生了不同的结果。(请原谅,我无法发布实际链接) 以下是每次试验的结果:Python 在Google自定义搜索API中从搜索结果中排除多个术语,python,python-3.x,google-custom-search,google-api-python-client,Python,Python 3.x,Google Custom Search,Google Api Python Client,根据,excludeTerms采用字符串值。如您所见,我尝试插入字符串数组,但效果不太好。实际上,我独立地测试了每一个术语,每次都产生了不同的结果。(请原谅,我无法发布实际链接) 以下是每次试验的结果: termsToExclude=' happypetsveterinarydotcom/ petdoctorxdotcom/ bestfriendsvetdotorg/ petpalanimalshelterdotcom/ termsToExclude=['happy','pet','vet
- termsToExclude=
'
happypetsveterinarydotcom/
petdoctorxdotcom/
bestfriendsvetdotorg/
petpalanimalshelterdotcom/
termsToExclude=['happy','pet','vet']
happypetsveterinarydotcom/
ollinghillspetclinicdotcom/
bestfriendsvetdotorg/
petpalanimalshelterdotcom/
termsToExclude='happy'
KriserDotcom/location/valencia/
瓦伦西亚动物医院网站/reviews.html
bestfriendsvetdotorg/
petpalanimalshelterdotcom/adopt.php
termsToExclude='pet'
teambusbydotcom/房地产新闻/家居与设计/60-design-happy-pets-from-round-the-world-photos-60
www.zmansiondotcom/
www.bestfriendequinedotcom/
disneyworld.disney.godotcom/entertainment/magic-kingdom/character-meet-goofy-donald/
termsToExclude='vet'
happypetsveterinarydotcom/医疗记录/我的宠物医疗记录/
www.statystudio6dotcom/en/motels.az.tucson.6002.html
langeanimalhospitaldotcom/josh friends/
petpalanimalshelterdotcom/event/purrfect瑜伽姿势/
excludeTerms
string
:标识不应出现在搜索结果中任何文档中的单词或短语
我不确定“搜索结果中的任何文档”的确切含义,但我通过这个过程发现,当使用单个字符串时,它似乎排除了带有字符串值的URL,,但当使用字符串数组时,它似乎根本没有相同的行为。有人能解释一下吗?或者,请解释是否有合适的方法在此关键字excludeTerms
参数中插入术语数组
不过,我想澄清一下,我试图实现的是插入字符串数组的功能,这样我的结果将专门排除包含termsToExclude
中术语的URL,这样我就可以在结果中获得更理想的URL。另外,请记住,当我使用单个字符串时,这会产生所需的结果,而数组的工作方式似乎不同
谢谢你提供的任何信息 excludeTerms是一个平面字符串,因此不确定在数组中传递什么行为 试一下
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)
完美的解决方案!这是我过度思考的典型案例。文档中没有关于排除多个单词的内容。这应该是显而易见的吗?我不能支持你的解决方案,但我可以肯定地说,这解决了我的问题!非常感谢=)
termsToExclude = 'happy pet vet'