【发布时间】:2013-08-09 13:47:13
【问题描述】:
我目前正在使用 Python 和 Mechanize 进行网站搜索,例如:site:somedomain.com 进入 BING。
它可以很好地提交到 bing 并返回输出 - 看起来像 Json?我似乎无法找到进一步解析结果的好方法。 是 JSON 吗?
我得到如下输出:
Link(base_url=u'http://www.bing.com/search?q=site%3Asomesite.com', url='http://www.somesite.com/prof.php?pID=478', text='SomeSite - Professor Rating of Louis Scerbo', tag='a', attrs=[('href', 'http://www.somesite.com/prof.php?pID=478'), ('h', 'ID=SERP,5105.1')])Link(base_url=u'http://www.bing.com/search?q=site%3Asomesite.com', url='http://www.somesite.com/prof.php?pID=527', text='SomeSite - Professor Rating of Jahan \xe2\x80\xa6', tag='a', attrs=[('href', 'http://www.somesite.com/prof.php?pID=527'), ('h', 'ID=SERP,5118.1')])Link(base_url=u'http://www.bing.com/search?q=site%3Asomesite.com', url='http://www.somesite.com/prof.php?pID=645', text='SomeSite - Professor Rating of David Kutzik', tag='a', attrs=[('href', 'http://www.somesite.com/prof.php?pID=645'), ('h', 'ID=SERP,5131.1')])
我想获取所有的网址,例如:
http://www.somesite.com/prof.php?pID=478
http://www.somesite.com/prof.php?pID=527
http://www.somesite.com/prof.php?pID=645
等等,所以url里面的属性
如何通过代码中的机械化进一步做到这一点?请记住,未来的一些 url 可能看起来像:
http://www.anothersite.com/dir/dir/dir/send.php?pID=100
谢谢!
【问题讨论】:
-
如果您使用 Microsoft 的 Azure API 来获取 Bing 结果,您可以将“format=JSON”作为 GET 参数附加到您的请求 URL。然后你会收到一个 JSON 字符串作为响应对象。
-
您能展示一个仅包含 url 的简短示例吗?附加 format=JSON 时是否重要?
-
你知道我上面的问题是什么类型的输出吗?我一辈子都找不到它
-
使用 Python 请求(不能作为注释缩进): req = requests.get(u'api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/…' % urllib.quote(q.encode('utf8'), ''), auth =('', u'YOU_API_KEY')) 结果 = req.json()['d']['results']
-
这看起来很可怕的评论......我会创建一个正确的答案,即使它不是 100% 准确的问题......
标签: python django json parsing mechanize