Question

I have a form in this site : http://cib.cf.ocha.ac.jp/bitool/MIX/ I want to submit the form and obtain the result(which I will parse to get the specific content) in python, so I am using urllib and BeautifulSoup (newbie in BeautifulSoup). My Code is as follows:

from bs4 import BeautifulSoup;
import urllib;
import urllib2;

post_parameters = {

'methods':'CF',
'aasequence':'EEEEEEEEEEEEEEEEEEE'
}
post_arguments = urllib.urlencode(post_parameters);
url = 'http://cib.cf.ocha.ac.jp/bitool/MIX/MIX.php';
request = urllib2.Request(url,post_arguments);
#response = urllib.urlopen(url,post_arguments);
response = urllib2.urlopen(request);

the_page = response.read();
soup=BeautifulSoup(the_page);
print soup; 

But the response it is generating is not having the contents in the pre tag which is there when I manually submit the form using the browser. The second pre tag in the document should have a formatted string.

Can anyone point out the mistake?

Was it helpful?

Solution

The site uses checkboxes to be able to select methods and uses a name of methods[] for the form element... Change your post_parameters to:

post_parameters = {    
    'methods[]':'CF',
    'aasequence':'EEEEEEEEEEEEEEEEEEE'
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top