1、从网址中获取网页内容
import urllib
import re
import sys
import string
sock = urllib.urlopen("http://www.hao123.com/")
strhtml = sock.read()
strhtml = unicode(strhtml, 'gb2312','ignore').encode('utf-8','ignore')
print(strhtml)
转载自:http://hi.baidu.com/kopla/blog/item/591335afde167ce8fbed505a.html
这个博客有不少python从网页获取内容的东东,很好
2、POST请求
以前在实现论坛自动发贴的时候写的代码,其中data部分就是你要提交的数据。
其实最好的方式就是你自己在提交一次注册信息的时候,抓包看一下post了什么东西,然后把data部分改成你要提交的东西,注意报文格式,就可以了。
#!/usr/bin/python
import cookielib, urllib2, urllib, sys, time
import httplib
http = httplib.HTTP('你要连接的host')
# write header
http.putrequest("POST", '/phpwind/post.php?')
http.putheader("User-Agent", "Mozilla/