首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Python脚本将在迭代循环中搜索google,并在搜索中使用引号

Python脚本将在迭代循环中搜索google,并在搜索中使用引号
EN

Stack Overflow用户
提问于 2016-02-25 05:51:16
回答 1查看 887关注 0票数 0

我正在尝试写一个python脚本,它将在循环中搜索google并输出顶部链接。我目前有这个:

代码语言:javascript
复制
import urllib
import json as m_json

for x in range(3, 5): 
query = 'x mile run'
query = urllib.urlencode ( { 'q' : query } )
response = urllib.urlopen ( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query ).read()
json = m_json.loads ( response )
results = json [ 'responseData' ] [ 'results' ]
for result in results:
    title = result['title']
    url = result['url']   # was URL in the original and that threw a name error exception
    print ( title + '; ' + url )

我的问题是修改搜索输入以接受双引号,因为我希望脚本搜索特定网站中的字符串。例如,我希望能够搜索:|"#1 Smartest Dog":dogs.com|。然后在每个循环之后迭代1。我尝试过的这些组合都失败了,我不确定如何让python忽略某些引号。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35613885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档