With this python code i can get whole html source
import mechanize
import lxml.html
import StringIO
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [("User-agent","Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13")]
sign_in = br.open("http://target.co.uk")
#the login url
br.select_form(nr = 0)
#accessing form by their index.
#Since we have only one form in this example, nr =0.
br.select_form(nr=0)
#Alternatively you may use this instead of the above line
#if your form has name attribute available.
br["username"] = "myusername"
#the key "username" is the variable that takes the username/email value
br["password"] = "myp4sw0rd"
#the key "password" is the variable that takes the password value
logged_in = br.submit()
#submitting the login credentials
logincheck = logged_in.read()
#reading the page body that is redirected after successful login
if "logout" in logincheck:
print "Login success, you just logged in."
else:
print "Login failed"
#printing the body of the redirected url after login
coding1_content = br.open("https://www.target.co.uk/levels/coding/1").read()
#accessing other url(s) after login is done this way
tree = lxml.html.parse(io.StringIO(coding1_content)
for ta in tree.findall("//textarea"):
if not ta.get("name"):
print(ta.text)
if "textarea" in coding1_content:
print "Textarea found."
else:
print "Textarea not found."
but what i need is get content of first textarea
tag which dont have name, my html source is like below
........
........
<textarea>this, is, what, i, want</textarea>
<textarea name="answer">i don't need it</textarea>
........
........
any help will be appreciated