Discussion:
POST value related question
james27
2009-10-12 15:20:44 UTC
Permalink
hello
im using mechanize .
i want to send some post value by use mechanize.
but problem is one of POST value in html source is
looks like below.

post.category.categoryNo=[*1]

anyway so i was tried several method but all failed.

here is source .
.
.
br = mechanize.browser()
br.select_form(nr=0)
br.form['post.category.categoryNo']=[*1]
br.form['contents.contentsValue'] = 'hello'
br.submit()
.
.

if anyone who know please help me .
thanks in advance.
--
View this message in context: http://www.nabble.com/POST-value-related-question-tp25857587p25857587.html
Sent from the Python - python-list mailing list archive at Nabble.com.
Diez B. Roggisch
2009-10-12 16:03:24 UTC
Permalink
Post by james27
hello
im using mechanize .
i want to send some post value by use mechanize.
but problem is one of POST value in html source is
looks like below.
post.category.categoryNo=[*1]
anyway so i was tried several method but all failed.
here is source .
.
.
br = mechanize.browser()
br.select_form(nr=0)
br.form['post.category.categoryNo']=[*1]
You are missing quotes here.

br.form['post.category.categoryNo']="[*1]"
Post by james27
br.form['contents.contentsValue'] = 'hello'
br.submit()
HTH, Diez
ken
2009-10-12 21:18:52 UTC
Permalink
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
2009-10-13 00:14:28 UTC
Permalink
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()

Continue reading on narkive:
Loading...