POST value related question

Discussion in 'Python' started by ken, Oct 12, 2009.

  1. ken

    ken Guest

    hello
    i have some problem to send POST value by use mechanize.
    i can't write my article to my blog site.

    here is full source. and what i want to do is, im posting my article
    to my blog site.
    thanks in advance.

    # -*- coding: cp949 -*-
    import mechanize
    import cookielib

    # Browser
    br = mechanize.Browser()

    # Cookie Jar
    cj = cookielib.LWPCookieJar()
    br.set_cookiejar(cj)

    # Browser options
    br.set_handle_equiv(True)
    br.set_handle_gzip(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)

    # Follows refresh 0 but not hangs on refresh > 0
    br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(),
    max_time=1)

    # Want debugging messages?
    #br.set_debug_http(True)
    #br.set_debug_redirects(True)
    #br.set_debug_responses(True)

    # User-Agent (this is cheating, ok?)
    br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-
    US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

    # Open some site, let's pick a random one, the first that pops in
    mind:
    r = br.open('http://nid.naver.com/nidlogin.login')
    html = r.read()
    #print html


    # Show the source
    #print html
    # or
    #print br.response().read()

    # Show the html title
    #print br.title()

    # Show the response headers
    #print r.info()
    # or
    #print br.response().info()

    # Show the available forms
    for f in br.forms():
    print f

    # Select the first (index zero) form
    br.select_form(nr=0)

    # Let's search
    br.form['id']='lbu142vj'
    br.form['sID']=['on']
    br.form['pw']='wbelryl'
    br.submit()
    #print br.response().read()
    r = br.open("http://www.naver.com")
    rs = r.read().decode('utf-8')
    #print rs
    r = br.open("http://blog.naver.com/PostWriteForm.nhn?
    Redirect=Write&blogId=lbu142vj&widgetTypeCall=true")
    rs = r.read()
    print rs

    for f in br.forms():
    print f

    br.select_form(nr=0)
    br.form['post.category.categoryNo']="[*1]"
    br.form['post.title']='subject'
    br.form['contents.contentsValue'] = 'content'
    br.submit()
     
    ken, Oct 12, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maxwell Hammer
    Replies:
    7
    Views:
    646
    Peter Hansen
    Jun 18, 2005
  2. sanjay
    Replies:
    1
    Views:
    382
    sanjay
    Oct 9, 2008
  3. james27

    POST value related question

    james27, Oct 12, 2009, in forum: Python
    Replies:
    1
    Views:
    267
    Diez B. Roggisch
    Oct 12, 2009
  4. ken

    POST value related question

    ken, Oct 13, 2009, in forum: Python
    Replies:
    0
    Views:
    263
  5. Wenjie

    perl CGI related: form post failure

    Wenjie, Sep 3, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    100
    Wenjie
    Sep 3, 2003
Loading...

Share This Page