【问题标题】:how to make xgoogle return google first page如何让xgoogle返回google首页
【发布时间】:2013-08-27 08:23:06
【问题描述】:

一直在尝试使用这个 xgoogle 在互联网上搜索 pdf 文件。我遇到的问题是,如果我搜索“Medicine:pdf”,返回给我的第一页不是谷歌返回的第一页,即如果我实际上使用谷歌....不知道这里有什么问题是 ma 代码

     try:
         page = 0   
         gs = GoogleSearch(searchfor)
         gs.results_per_page = 100
         results = []
         while page < 2:
             gs.page=page
             results += gs.get_results()
             page += 1
     except SearchError, e:
            print "Search failed: %s" % e             
     for res in results:
         print res.desc

如果我真的使用谷歌网站搜索查询,谷歌为我显示的第一页是: 标题 : 医学 - 英国文化协会
描述 :英国的医学培训有着悠久的卓越历史,并且......世界各地的医学领袖都接受过他们的医学教育。
网址:http://www.britishcouncil.org/learning-infosheets-medicine.pdf
但是,如果我使用我的 python Xgoogle 搜索,我会得到:
Python OutPut
说明:UCM175757.pdf
标题:我家中的药物:学生演示 - 食品和药物 ...
网址:http://www.fda.gov/downloads/Drugs/ResourcesForYou/Consumers/BuyingUsingMedicineSafely/UnderstandingOver-the-CounterMedicines/UCM175757.pdf

【问题讨论】:

    标签: python pdf xgoogle


    【解决方案1】:

    我注意到在浏览器中使用 xgoogle 和使用 google 是有区别的。我不知道为什么,但你可以试试 google custom search api。 google自定义搜索api可以为您提供更接近的结果,并且没有被google禁止的风险(如果您在短时间内多次使用xgoogle,您将返回错误而不是搜索结果)。

    首先您必须注册并启用您在 google 中的自定义搜索以获取密钥和 cx https://www.google.com/cse/all

    api格式为:

    'https://www.googleapis.com/customsearch/v1?key=yourkey&cx=yourcx& alt=json&q=yourquery'

    • customsearch 是您要使用的 google 功能,在您的情况下我认为是 customsearch
    • v1 是你应用的版本
    • yourkey 和 yourcx 由 google 提供,您可以在仪表板上找到它
    • yourquery 是您要搜索的字词,在您的情况下是“Medicine:pdf”
    • json为返回格式

    示例返回google自定义搜索结果的前3页:

    import urllib2
    import urllib
    import simplejson
        def googleAPICall():    
            userInput = urllib.quote("global warming")    
            KEY = "##################"  # get yours
            CX = "###################"  # get yours
    
            for i in range(0,3):
                index = i*10+1 
                url = ('https://scholar.googleapis.com/customsearch/v1?'    
                       'key=%s'
                       '&cx=%s'
                       '&alt=json'
                       '&q=%s'
                       '&num=10'
                       '&start=%d')%(KEY,CX,userInput,index)  
    
                request = urllib2.Request(url)
                response = urllib2.urlopen(request)
                results = simplejson.load(response)
    

    【讨论】:

      猜你喜欢
      • 2019-01-04
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多