Python, parse html form

how I can get input from html forms on other sites? I want it to return a dictionary such as:

form = [('name' = 'somename', 'type' = 'text', 'value':''},{' name' = 'somename', 'type' = 'submit', 'value': ' submit ').

Sorry for my English.

-------------Problems Reply------------

you probably wont be able to retrieve form data from other users on other sites. If you wish to use a script to send data to a form, mechanize is one tool that makes this quite easy.

Look at mechanize, lxml.html and BeatifulSoup.

Yeah mechanize is sweet !

import mechanize

# Browser
br = mechanize.Browser()
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)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
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')]

# we inspect the all form element in the http://stackoverflow.com
br.open('http://stackoverflow.com')
for form in br.forms():
print form

Category:python Views:1 Time:2010-08-22
Tags: html forms python

Related post

  • Advice on Python Parser Generators 2009-11-21

    Hey guys, this is my first question here on Stack Overflow and I was wondering if I could ask the advice of people who know a bit more about Python and Parser Generators than I do. I've been given a task where I have to create a parser for a simple C

  • What is a good python parser for a google-like search query? 2010-03-02

    For some search-based code (in Python), I need to write a query syntax parser that would parse a simple google like query syntax. For example: all of these words "with this phrase" OR that OR this site:within.site filetype:ps from:lastweek As search

  • Python parser script layout 2010-08-24

    I'm writing a simple Python parser, where I loop over each line in a file, and prosess it further if the right conditions are met. My short start: def identify(hh_line): if(re.match(regex.new_round, hh_line)): m = re.match(regex.new_round, hh_line) #

  • Python parser Module tutorial 2011-03-19

    I am writing an application which reads an input file that currently has its own grammar, which is processed by lex/yacc. I'm looking to modify this so as to make this input file a Python script instead, and was wondering if someone can point me to a

  • Compiling Jython From Source generate org.python.parser directory 2011-04-15

    Hello I am trying to compile the Jython Java Source Code from subversion. But it fails because there is no parser directory it should be org.python.parser in org/python/parser. I read that this folder you need to generate. Any ideas how would be grea

  • python parser module - examples 2011-04-21

    Does anyone have a simple or some examples on how to use python parser module. A link to the examples or some simple examples here would be helpful to get me started. --------------Solutions------------- From Python Docs Also: One of the links mentio

  • is there something like a python parser for j2me? 2011-08-10

    I have a phone that does java and I want to program in bed, on my phone. Is there any (python) parser on java basis for J2me, possibly? is there a website where I can write and test python code? Then I could code in Opera. --------------Solutions----

  • Python parser for Python-like language 2012-02-23

    I'm looking to write a Python import filter or preprocessor for source files that are essentially Python with extra language elements. The goal is to read the source file, parse it to an abstract syntax tree, apply some transforms in order to impleme

  • Python: parsing JSON-like Javascript data structures (w/ consecutive commas) 2012-04-07

    I would like to parse JSON-like strings. Their lone difference with normal JSON is the presence of contiguous commas in arrays. When there are two such commas, it implicitly means that null should be inserted in-between. Example: JSON-like: ["foo",,,

  • Help me find an appropriate ruby/python parser generator 2009-06-04

    The first parser generator I've worked with was Parse::RecDescent, and the guides/tutorials available for it were great, but the most useful feature it has was it's debugging tools, specifically the tracing capabilities ( activated by setting $RD_TRA

  • python: parse HTTP POST request w/file upload and additional params 2009-10-11

    The task is simple: on the server side (python) accept an HTTP POST which contains an uploaded file and more form parameters. I am trying to implement upload progress indicator, and therefore I need to be able to read the file content chunk-by-chunk.

  • Python parsing bracketed blocks 2009-10-30

    What would be the best way in Python to parse out chunks of text contained in matching brackets? "{ { a } { b } { { { c } } } }" should initially return: [ "{ a } { b } { { { c } } }" ] putting that as an input should return: [ "a", "b", "{ { c } }"

  • Python: parsing date with timezone from an email 2009-11-24

    I am trying to retrieve date from an email. At first it's easy: message = email.parser.Parser().parse(file) date = message['Date'] print date and I receive: 'Mon, 16 Nov 2009 13:32:02 +0100' But I need a nice datetime object, so I use: datetime.strpt

  • Python+parsing custom config file 2010-02-23

    I have a quite big custom made config file I need to extract data from once a week. This is an "in house" config file which doesn't comply to any know standard like INI or such. My quick and dirty approach was to use re to search for the section head

  • python parsing url after string 2010-03-01

    I want to extract a string from a url (link). That string is in a <h3></h3> tag. link = http://www.test.com/page.html Content of link: <h3>Text here</h3> What would be an elegant way to first get the content/sourcecode of page

  • Python parse comma-separated number into int 2010-06-01

    Possible Duplicate: How do I use Python to convert a string to a number if it has commas in it as thousands separators? How would I parse the string 1,000,000 (one million) into it's integer value in Python? --------------Solutions------------- >

  • Python parsing files 2010-07-02

    I need to know the best approach for the following scenario lets say we have some huge file which logs the output of the compilation and there are couple of error patterns which I want to test against this file, for eg. error patterns could be - : er

  • Microsoft Powerpoint Python Parser 2010-07-05

    I am looking for a python based microsoft office parser - specifically powerpoint. I want to be able to parse PPT in python and extract things like text and images from the powerpoint file. Is there a library available? --------------Solutions-------

  • Python parsing: lxml to get just part of a tag's text 2010-07-21

    I'm working in Python with HTML that looks like this. I'm parsing with lxml, but could equally happily use pyquery: <p><span class="Title">Name</span>Dave Davies</p> <p><span class="Title">Address</span>123 G

  • Python: parsing XML document while preserving entities 2010-08-17

    I wanted to ask what known existing Python 2.x libraries there are for parsing an XML document with built-in DTD without automatically expanding the entities. (File in question for those curious: JMdict.) It seems lxml has some option for not parsing

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.100 (s). 11 q(s)