1. 程式人生 > >web crawling(plus2) get and post

web crawling(plus2) get and post

get utf-8 mini req raw request awl and open

http request:

**************************************************************
get:****.com/sss?aa=bb&cc=dd ("aa"=key;"bb"=value)

#Author:Mini
#!/usr/bin/env
import urllib.request
keywd="Mini"
url="http://www.baidu.com/s?wd="+keywd+"&ie=utf-8&tn=96542061_hao_pg"
req=urllib.request.Request(url)
data2=urllib.request.urlopen(req).read()
f1=open("E:/2.html","wb")
f1.write(data2)
f1.close()

#Author:Mini
#!/usr/bin/env
import urllib.request
keywd="Mini王 "
keywd=urllib.request.quote(keywd)
url="http://www.baidu.com/s?wd="+keywd+"&ie=utf-8&tn=96542061_hao_pg"
req=urllib.request.Request(url)
data2=urllib.request.urlopen(req).read()
f1=open("E:/2.html","wb")
f1.write(data2)
f1.close()


******************************************


 
import urllib.parse
url1="http://www.iqianyue.com/mypost/"
data3=urllib.parse.urlencode({
"name":"[email protected]",
"pass":"123456sd"
}).encode("utf-8")
req1=urllib.request.Request(url1,data3)
data3=urllib.request.urlopen(req1).read()
fh=open("E:/3.html","wb")
fh.write(data3)
fh.close()

 



web crawling(plus2) get and post