Okay, so I’m using Mechanize to log into Google groups and manually add a member to the group.
I’ve been able to successfully log in and navigate to the appropriate page. On this page there is a textarea box where you can add the e-mail addresses you want to manually add to the group.
Here is the html for the textarea:
<textarea class="gwt-TextArea GFBTXDWBA-" id="gwt-uid-224" aria-haspopup="false" dir="" role="combobox" aria-autocomplete="list" aria-activedescendant=""></textarea>
When I run a loop:
for form in br.forms():
print form
The only form that gets returned is the ‘Search members’ form at the top, none of the text areas appear.
I don’t think select_form is going to work because it’s not actually a form. There is an ‘Add’ button on the top left of the screen that submits the input from the textarea here is the HTML for the ‘Add’ button:
<input type="text" tabindex="-1" role="presentation" style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow: hidden; position: absolute;">
What I’m trying to do is add an e-mail address to the text area and submit it. Any help would be greatly appreciated.
Here is my full code:
import mechanize
import cookielib
br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
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')]
r = br.open('https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fgroups.google.com%2Fd%2Fmanagemembers%2Ftesttgroup123456%2Fadd&hl=en&service=groups2&passive=true')
html = r.read()
br.select_form(nr=0)
br.form['Email']='myUsername'
br.form['Passwd']='myPassword'
br.submit()
for form in br.forms():
print form
A better approach to this is to use Google’s Provisioning API
https://developers.google.com/google-apps/provisioning/