open html page for parsing

L

luca72

Hello i have a simple question:
up to now if i have to parse a page i do as follow:
import urllib
site = urllib.urlopen('http://www.blabla.ooo')
list_a = site.readline()
site.close()
__and then i make my work__

Now i have the site that is open by an html file like this:
<table>
<b>insert the password</b>
<form name="form_a" method="POST" action="http://lalal.hhdik/
lolo.php">
<input type="passwd" name="password" value="password"></input>;
<input type="submit" name="Entra" value="entra"></input>;
</form>
</table>


</div>
<script type="text/javascript">
document.form_a.submit();
</script>

this is in a file called example.html

how can i open it with urllib
 
C

Chris Rebert

Hello i have a simple question:
up to now if i have to parse a page i do as follow:
import urllib
site = urllib.urlopen('http://www.blabla.ooo')
list_a = site.readline()
site.close()
__and then i make my work__

Now i have the site that is open by an html file like this:
               <table>
<b>insert the password</b>
<form name="form_a" method="POST" action="http://lalal.hhdik/
lolo.php">
                               <input type="passwd" name="password" value="password"></input>;
                               <input type="submit" name="Entra"value="entra"></input>;
                       </form>
               </table>


</div>
<script type="text/javascript">
document.form_a.submit();
</script>

this is in a file called example.html

how can i open it with urllib

Assuming you meant "How do I submit the form in example.html and get
the resulting response page?", use urllib.urlencode() to encode the
form's key-value pairs, and then pass the encoded result as the `data`
argument to urllib.urlopen(). Or use something like Selenium
(http://seleniumhq.org/ ), mechanize
(http://wwwsearch.sourceforge.net/mechanize/ ), or Scrapy
(http://scrapy.org/ ) that emulates/drives a web browser and lets you
fill out forms programatically.

Cheers,
Chris
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top