我试图用python从google搜索引擎中搜索一些短语。我给输入字符串'DVD player'
并用Google搜索包含这两个词的页面,并用DVD+player
术语形式化搜索。但我想搜索准确的短语。我试图用"\"DVD plyar\""
替换这个词,这样谷歌就可以搜索到"DVD player"
,但似乎没有用。在
以下是从其他问题中选择的代码。在
import json
import urllib.request
def showsome(searchfor):
query = urllib.parse.urlencode({'q': searchfor})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query
search_response = urllib.request.urlopen(url)
search_results = search_response.read().decode('utf8')
results = json.loads(search_results)
data = results['responseData']
print ('Total results: %s' % data['cursor']['estimatedResultCount'])
hits = data['results']
print ('Top %d hits:' % len(hits))
for h in hits: print (' ', h['url'])
print ('For more results, see %s' % data['cursor']['moreResultsUrl'])
showsome("\"DVD player\"")
目前没有回答
相关问题 更多 >
编程相关推荐