gpt4 book ai didi

python - 从 Google Custom Search API 的搜索结果中排除多个字词

转载 作者:行者123 更新时间:2023-11-28 22:18:06 25 4
gpt4 key购买 nike

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 documentationexcludeTerms 采用字符串值。如您所见,我尝试插入一个字符串数组,但效果不佳。我实际上独立测试了每个术语,每次都会产生不同的结果。 (请原谅 dotcom,因为我无法发布实际链接)

这是每个测试的结果:

  • termsToExclude = ''
    happypetsveterinarydotcom/
    petdoctorxdotcom/
    bestfriendsvetdotorg/
    petpalanimalshelterdotcom/

    termsToExclude = ['happy','pet','vet']
    happypetsveterinarydotcom/
    ollinghillspetclinicdotcom/
    bestfriendsvetdotorg/
    petpalanimalshelterdotcom/

    termsToExclude = '快乐'
    krisersdotcom/location/valencia/
    valenciaanimalhospitaldotcom/reviews.html
    bestfriendsvetdotorg/
    petpalanimalshelterdotcom/adopt.php

    termsToExclude = '宠物'
    teambusbydotcom/real-estate-news/home-and-design/60-design-happy-pets-from-around-the-world-60-photos
    www.zmansiondotcom/
    www.bestfriendequinedotcom/
    disneyworld.disney.godotcom/entertainment/magic-kingdom/character-meet-goofy-donald/

    termsToExclude = 'vet'
    happypetsveterinarydotcom/medical-records/my-pets-medical-records/
    www.staystudio6dotcom/en/motels.az.tucson.6002.html
    langeanimalhospitaldotcom/josh-friends/
    petpalanimalshelterdotcom/event/purrfect-poses-yoga/

现在..

Google 的 vague user-friendly documentation 声明如下:

excludeTerms string :标识不应出现在搜索结果的任何文档中的单词或短语.

我不确定“搜索结果中的任何文档”到底是什么意思,但我通过这个过程发现的是,当使用单个字符串时,它似乎排除了带有字符串值,但是当使用字符串数组时,它似乎根本没有相同的行为。谁能解释一下?或者请解释是否有适当的方法可以在此关键字 excludeTerms 参数中插入一组术语?

不过我想澄清一下,我想要完成的是能够插入一个字符串数组,这样我的结果将专门排除包含 termsToExclude 中的术语的 URL,这样我可以在我的结果中获得更理想的 URL。另外,请记住,当我使用单独的字符串时,会产生所需的结果,而数组的工作方式似乎不同。

感谢您提供任何信息!

最佳答案

excludeTerms 是一个平面字符串,因此不确定您将在数组中传递什么行为。

尝试一下

termsToExclude = 'happy pet vet'

关于python - 从 Google Custom Search API 的搜索结果中排除多个字词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50762300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com