柳暗花明笔记

    python经典post模拟-这玩意真的很强大

    所属分类:[ java&python&node ] 猫哲学家 发表于:2014-09-09 23:49 浏览:541

    #!/usr/bin/python
    #-*-coding:utf-8-*-

    import HTMLParser
    import urlparse
    import urllib
    import urllib2
    import cookielib
    import string
    import re

    hosturl = 'http://XXX.com/'

    posturl = 'http://XXX.com/DealCenterLogin.aspx?codev=9196'

    cj = cookielib.LWPCookieJar()
    cookie_support = urllib2.HTTPCookieProcessor(cj)
    opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler)
    urllib2.install_opener(opener)

    h = urllib2.urlopen(hosturl)

    headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
    'Referer' : '******'}

    postData = {'str_username' : 'XXX',
    'str_userpwd' : 'XXX'}

    postData = urllib.urlencode(postData)

    request = urllib2.Request(posturl, postData, headers)
    #print request
    response = urllib2.urlopen(request)
    text = response.read()
    print text


    postData1 = {'input_y_str_PROJNAME' : '阳光天地', 'input_y_str_ADDRESS' : 'sfee'}

    posturl1 = "http://XXX.com/MAgent/house/InputSave.aspx?flag=2&haveMultipleCity=False&city=%C9%EE%DB%DA&isWireless=0"

    postData1 = urllib.urlencode(postData1)

    request1 = urllib2.Request(posturl1, postData1, headers)
    #print request1
    response1 = urllib2.urlopen(request1)
    text1 = response1.read()
    print text1

     

    这玩意真的很强大,很多php curl snoopy 搞不得的它都可以哦.

    标签: python 
    上一编文章 SyntaxError: Non-ASCII character '\xe9' in file 解决方法 下一编文章 ubuntu 14.04安装mongoDB
    最近文章
    发表评论