该博文涵盖了如下内容:
1. WSDL
2. SOAPpy
3.面向对象封装方法
1. WSDL
2. SOAPpy
3.面向对象封装方法
- #encoding=utf-8
- """
- Search Google from the command line
- url : http://pywebsvcs.sourceforge.net/
- Install http://ncu.dl.sourceforge.net/project/pywebsvcs/SOAP.py/SOAPpy%200.11.0/SOAPpy-0.11.0.tar.gz
- author : edison & dive in python
- """
- from SOAPpy import WSDL
- #see http://code.google.com/intl/zh-CN/apis/soapsearch/api_faq.html
- WSDLFILE = 'http://api.google.com/GoogleSearch.wsdl'
- APIKEY = 'key'
- #建立web service
- _server = WSDL.Proxy(WSDLFILE)
- #打印soap输入,输出
- _server.soapproxy.config.dumpSOAPOut = 1
- _server.soapproxy.config.dumpSOAPIn = 1
- def search(q):
- print "print server methods"
- print _server.methods.keys()
- """Search Google and return list of {title, link, description}"""
- results = _server.doGoogleSearch(
- APIKEY, q, 0, 10, False, "", False, "", "utf-8", "utf-8")
- return [{"title": r.title.encode("utf-8"),
- "link": r.URL.encode("utf-8"),
- "description": r.snippet.encode("utf-8")}
- for r in results.resultElements]
- if __name__ == '__main__':
- import sys
- if sys.argv[1] :
- for r in search(sys.argv[1])[:5]:
- print r['title']
- print r['link']
- print r['description']
- if __debug__:
- #只打印前5条
- for r in search("tl50")[:5]:
- print r['title']
- print r['link']
- print r['description']
- pass

本文介绍如何使用SOAPpy库与Google搜索API进行交互,包括安装库、配置及调用API搜索功能,返回搜索结果并解析。

9110

被折叠的 条评论
为什么被折叠?



