Hi,
I have been trying to do this for a few days now ... I'd appreciate any help or insights ...
Basically I want to enter text into a web 'textarea' automatically ... here is what I
thought I should have ... import urllib
import urllib2
import cookielib
url2 = "someUrl"
url = "someOtherUrl"
#Create empty cookie jar.
cj = cookielib.LWPCookieJar()
#Install cookie handler for urllib2.
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(c j))
urllib2.install_opener(opener)
request = urllib2.Request(url, None)
f = urllib2.urlopen(request)
f.close()
# this is just to log into the site first ...
data = urllib.urlencode({"username": "xxxxx", "password" : "somePassword"})
request = urllib2.Request(url, data)
f = urllib2.urlopen(request)
html = f.read()
#print html
#print data
f.close()
request2 = urllib2.Request(url2, None)
t = urllib2.urlopen(request2)
t.close()
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }
#Parse the html here (html contains the page markup).
data2 = urllib.urlencode({"message" : "rows5>blah", "recipients[0]" : "xxxxxxx"})
#print data2
request2 = urllib2.Request(url2, data2, headers)
t = urllib2.urlopen(request2)
html2 = t.read()
print html2
t.close()
but I'm guessing that 'textarea' doesn't have a value attribute .. it looks like the text just goes between the two tags <textarea></textarea>
So how do I go about submitting predetermined text into the textarea? Do I have to parse the page and replace the whole 'textarea' section including my inputted text?
Hope you can help me,
4 10570 - import urllib
-
import urllib2
-
import cookielib
-
-
url2 = "someUrl"
-
url = "someOtherUrl"
-
-
#Create empty cookie jar.
-
cj = cookielib.LWPCookieJar()
-
#Install cookie handler for urllib2.
-
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
-
urllib2.install_opener(opener)
-
-
-
request = urllib2.Request(url, None)
-
f = urllib2.urlopen(request)
-
f.close()
-
-
# this is just to log into the site first ...
-
data = urllib.urlencode({"username": "xxxxx", "password" : "somePassword"})
-
request = urllib2.Request(url, data)
-
f = urllib2.urlopen(request)
-
-
html = f.read()
-
#print html
-
#print data
-
f.close()
-
-
-
request2 = urllib2.Request(url2, None)
-
t = urllib2.urlopen(request2)
-
t.close()
-
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
-
headers = { 'User-Agent' : user_agent }
-
#Parse the html here (html contains the page markup).
-
data2 = urllib.urlencode({"message" : "rows5>blah", "recipients[0]" : "xxxxxxx"})
-
#print data2
-
request2 = urllib2.Request(url2, data2, headers)
-
t = urllib2.urlopen(request2)
-
html2 = t.read()
-
print html2
-
t.close()
but I'm guessing that 'textarea' doesn't have a value attribute .. it looks like the text just goes between the two tags <textarea></textarea>
What is the textarea that you speak of?
What is the textarea that you speak of?
Sorry I should have said ... the textarea i'm speaking about is an area
in a web-form that will accept alot of text (depending on the limits the
web-master has set). The html code for this is : -
<div class="form-row">
-
<div class="form-col-a"><label for="message">Message </label></div>
-
<div class="form-col-b"><textarea style="OVERFLOW: auto"
-
wrap="SOFT" name="message" tabindex="1" id="message" cols="25"
-
rows="5"></textarea></div>
-
Usually the textarea 'value' goes just before the "</textarea>" part ... but I want to
fill this in automatically ... usually you can do this for a text input field using 'urllib.urlencode' and 'urllib2.Request' but I don't think this will work for a textarea and I was wondering if anyone else has done this?
It seems like it should be pretty easy to do but I am stumped!
Thanks
A link to a Python program that claims to do this. I haven't tried it but have wondered how well it works. http://wwwsearch.sourceforge.net/ClientForm/ Please post back on whether it works or not.
Hi,
Thanks for the reply ... I finally got this working ... thanks to ClientForm ... this
is a great module ... very easy to use.
Basically, I wanted to log into a website (using password and username) navigate to a page and enter details into a form and submit it. I wanted to do this so I could send sms text messages from the command line (without a browser open).
Here is the code that I wrote to do the task ...
any comments/suggestions are welcome :
You run it from command line using : python progname.py "your message" number -
#!/scisoft/bin/python2.4
-
-
import time
-
import urllib
-
import urllib2
-
import cookielib
-
import ClientForm
-
from HTMLParser import HTMLParser
-
import sre
-
-
#----------------- START WEBSITE URLS ---------------------------#
-
-
url = "www.someURL.com/login"
-
url2 = "www.someURL.com/webtext/index.jsp"
-
url3 = "www.someURL.com/myv/messaging/webtext/Process.shtml"
-
-
-
#----------------- START USER VARIABLES --------------------------#
-
-
etag = "None"
-
user_agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT"
-
protocol = 'https://'
-
username = YOUR_USERNAME
-
password = YOUR_PASSWORD
-
maxMesgLen = 160
-
-
#--------------------------- END ---------------------------------#
-
-
-
def sendSMS(textmessage,*number):
-
"""
-
-
"""
-
-
print "Sending ........"
-
-
lenMessage = countCharacters(textmessage)
-
# Check to see if message is less than 160 characters
-
overFlowText = lenMessage - maxMesgLen
-
if lenMessage <= maxMesgLen:
-
-
-
#Create empty cookie jar.
-
cj = cookielib.LWPCookieJar()
-
-
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
-
urllib2.install_opener(opener)
-
-
request1 = urllib2.Request(protocol+url, None)
-
t1 = opener.open(request1)
-
forms = ClientForm.ParseResponse(t1, backwards_compat=False)
-
t1.close()
-
-
form = forms[1]
-
form["username"] = username
-
form["password"] = password
-
# Check the keep me logged on checkbox
-
form.find_control("keeplogon").items[0].selected = True
-
#print form
-
-
request11 = form.click()
-
request11.add_header("User-Agent", user_agent)
-
response11 = opener.open(request11)
-
-
-
-
request2 = urllib2.Request(protocol+url2, None)
-
t = opener.open(request2)
-
#print t.geturl()
-
#print t.info()
-
#print "This is the code for the webtext page: ",t.code
-
forms = ClientForm.ParseResponse(t, backwards_compat=False)
-
t.close()
-
-
-
form = forms[1]
-
form["message"] = textmessage
-
-
numberList = list(*number)
-
noArgs = len(numberList)
-
for i,recip in enumerate(numberList):
-
form["recipients[%d]" % i] = recip
-
-
-
request3 = form.click()
-
-
request3.add_header('User-Agent', user_agent)
-
request3.add_header('Referer', protocol+url2)
-
request3.add_header('Charset', "utf-8")
-
request3.add_header('If-None-Match', etag)
-
request3.add_header('Content-type', "text/html")
-
-
#This is vital for the message to send correctly!!!
-
time.sleep(2)
-
-
response2 = opener.open(request3)
-
-
# Was your message sent successfully???
-
success = response2.geturl()
-
recipList = []
-
if success == protocol+url3 :
-
for recip in numberList:
-
if recip != "":
-
recipList.append(recip)
-
print "Your message was sent successfully to : ", recipList
-
else :
-
print "Your message was _NOT_ sent!!!!!!"
-
#print response2.info() # headers
-
#print 'This is the code :', response2.code
-
##print response2.read()
-
response2.close()
-
-
-
-
# Get number of remaining Messages ... left
-
reqMesgRem = urllib2.Request(protocol+url2, None)
-
req = urllib2.urlopen(reqMesgRem)
-
dataMesgRem = req.read()
-
# find the number of remaining text messages left and the renewal date
-
matches = sre.findall('<span class="msg-total">(.*?)</span>', dataMesgRem)
-
print " "
-
print "# Messages Remaining -----> ", matches[0]
-
print "Renewal Date is -----> ", matches[1]
-
req.close()
-
-
else :
-
print "Message too long by", overFlowText,"!"
-
-
-
def countCharacters(message):
-
"""
-
Counts the number of characters in the message
-
"""
-
-
charCount= []
-
for char in message:
-
charCount.append(char)
-
messageLength = len(charCount)
-
return messageLength
-
-
-
-
if __name__ == "__main__":
-
import sys
-
if len(sys.argv) < 8:
-
sendSMS(sys.argv[1],sys.argv[2:])
-
else :
-
print "ERROR : You have entered too many numbers!!!"
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: LarsenMTL |
last post by:
I have a long running python cgi which in the end returns a link to a
pdf file. While it runs it generates a log that uses stdout right into
the html. I use the sys.stdout.flush() to make this log...
|
by: David |
last post by:
It's sad to say, but when using the AOL web site, like to send an
email, they have a nifty capability such that when a window is
resized, the textarea where the message is input expands not only...
|
by: Werner |
last post by:
Hello,
how can fill automatically a textarea when opening a webpage.
I want to do this by a function that has been raised in js file.
thx
|
by: PTM |
last post by:
I'm no javascript pro but have to write up a rather large system. Now
I'm stuck with a problem.
I would like to make a webpage where a customer vould edit short pieces
of text, abt 200-300 chr....
|
by: JM |
last post by:
Before storing information from a form in database I perform follwing
operations on it :
$path =
mysql_real_escape_string(strip_tags(trim(urldecode($_POST))));
$summary =...
| |
by: Adrian Smith |
last post by:
This may be more a cgi thing than a Python one, but I'm trying to get
this page:
http://adrian10.phpwebhosting.com/trial.html
consisting basically of this:
<FORM...
|
by: babacrash |
last post by:
Hi,
I'm designing a webpage that allows the user to add small bubbles like comics bubbles to place comments on the page. These bubbles are divs containing an image (for the border of the bubble)...
|
by: kettle |
last post by:
Hi,
I have a simple web page which is composed of a flash audio player
(jwmp3player) and a form with a textarea box. I have noticed some
very odd behaviour which I cannot puzzle out.
If I...
|
by: Coldfire |
last post by:
I was wondering if its possible to get text in the textarea, on some webpage, and show it with some rotation like 45 degree angle, like a signature at the bottom.
one way is to save the textarea...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |