I’ve done my first python script, and also my first mechanized Browser, very nice. But…
it returns some fields as ’empty string’ , which in this case is : “&\nbsp;” (back-slashe is mine, otherwise nothing appears.)
Has anyone experienced this before with mechanize.Browser?
Here is my code:
#!/usr/bin/env python
import mechanize
import cookielib
# Browser
br = mechanize.Browser()
# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
# Browser options
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)
# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
# Want debugging messages?
#br.set_debug_http(True)
#br.set_debug_redirects(True)
#br.set_debug_responses(True)
# User-Agent (this is cheating, ok?)
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://192.168.2.141/webacs/welcomeAction.do')
br.select_form(nr=0)
br.form['username']='root'
br.form['password']='bla bla bla'
submit = br.submit()
import time
# just in case is about rendering time, which is not.
time.sleep(10)
wcs_web = br.response().read()
file = open("wcs_web.html",'w')
file.write(wcs_web)
file.close()
And in file wcs_web.html I find this:
<tr>
<th class="navAlarm" width="92">Malicious AP</th>
<td id="rogueCritical" class="navAlarmNothing" align="right" width="23"> </td>
<td id="rogueMajor" class="navAlarmNothing" align="right" width="23"> </td>
<td id="rogueMinor" class="navAlarmNothing" align="right" width="23"> </td>
</tr>
Where it gives me ‘&\nbsp;'(again, backslash is mine or nothing shows up) it should be ‘0’.
Anyone knows why is this? And how it can be fixed?
Could javascript be responsible for turning the &\nbsp; into 0? Mechanize doesn’t execute javascript.