Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8368375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:22:31+00:00 2026-06-09T13:22:31+00:00

I’m trying to fill out a form containing a textarea element. I’m using Python

  • 0

I’m trying to fill out a form containing a textarea element. I’m using Python with the BeautifulSoap and mechanize modules (stuck on 2.6.5 on FreeBSD 8.1 with the latest modules in the FreeBSD repository: BeautifulSoup 3.1.0.1 and mechanize 0.2.1).

The problem with BeautifulSoap is it doesn’t properly set textarea contents (I can try soup.textarea.insert(0, "FOO") or even soup.textarea.contents = "FOO", but once I check the current value with soup.textarea, I still see the old HTML tags with no content between them:

<textarea name="classified_description" class="classified_textarea_text"></textarea>

The problem with mechanize is it only seems to operate on true forms. Per the HTML I’m parsing below, this is not really a form, but rather a set of divs with input items inside.

How can I use Python or either of these modules to set the value of this textarea element?

<div class="classified_field">
            <div class="classified_input_label">Description</div>
            <div class="classified_textarea_div">
                <textarea name="classified_description" id="classified_description" class="classified_textarea_text"></textarea>
            </div>
            <div class="site_clear"></div>
        </div>

I’d tried Vladimir’s technique below, and while it works with his example, it does not work in my production code for some reason. I’m able to use .find() to get the textarea, but the .insert() is giving me grief. Here’s what I have so far:

>>> soup.find('textarea', {'name': 'classified_description'})                  
<textarea name="classified_description" class="classified_textarea_text"></textarea>
>>> soup.find('textarea', {'name': 'classified_description'}).insert(0, "some text here")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/site-packages/BeautifulSoup.py", line 233, in insert
  newChild.nextSibling.previousSibling = newChild
AttributeError: 'unicode' object has no attribute 'previousSibling'
>>> 

Anyone know why this would through the unicode error? Clearly my soup object is not just a unicode string because I successfully use .find.

SOLUTION:
Vladimir’s solution is correct, but it’s possible for real-world HTML to generate a malformed start tag error in BeautifulSoup 3.1 (official reason here). After downgrading to BeautifulSoup 3.0.8, everything worked fine. When I posted the initial question, I had to do some jury rigging to get mechanize to read() into the BeautifulSoup object so as not to geht the malformed start tag error. This caused a uencode sting to be created instead of a BeautifulSoup object. Correcting my mechanize code with the older BeautifulSoup has caused the desired behavior.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:22:32+00:00Added an answer on June 9, 2026 at 1:22 pm

    Here is an example using BeautifulSoup:

    from BeautifulSoup import BeautifulSoup
    
    soup = BeautifulSoup('<textarea name="classified_description"></textarea>')
    soup.find('textarea', {'name': 'classified_description'}).insert(0, 'value')
    assert str(soup) == '<textarea name="classified_description">value</textarea>'
    

    BeautifulSoup documentation on modifying the parse tree describes such transformations in details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to select an H1 element which is the second-child in its group
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.