0

一直在尝试使用此 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 _学生 - 食品和药物 ... 网址:http ://www.fda.gov/downloads/Drugs/ResourcesForYou/Consumers/BuyingUsingMedicineSafely/UnderstandingOver-the-CounterMedicines/UCM175757.pdf


4

1 回答 1

0

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

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

api格式为:

' https://www.googleapis.com/customsearch/v1 ? _ _ _ 键=您的密钥& cx=您的 cx & alt=json & q=您的查询'

  • customsearch 是您要使用的谷歌功能,在您的情况下,我认为它是 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)
于 2014-04-30T16:27:39.743 回答