$ python -m SimpleHTTPServer 8000在本地开启一个 http 的服务器。这可以方便调试简单的 HTML 页面。通过 CGI 甚至可以调试复杂一点的 AJAX。
python 另外有一个 django 可以实现一个比较复杂的 HTTP 服务器。后面稍微研究下。
$ python -m SimpleHTTPServer 8000在本地开启一个 http 的服务器。这可以方便调试简单的 HTML 页面。通过 CGI 甚至可以调试复杂一点的 AJAX。
import httplib
conn = httplib.HTTPConnection( 'www.yahoo.com' )
res = conn.request( 'GET', '/', headers = {'User-Agent': ua, 'Cookie': cookie })
if res.status == 200:
html = res.read()
# parse the html
else:
print res.status, res.reason