473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

mechanize select_form issue..

hi...

update to an ongoing issue i've been having regarding html/Browser and
selecting forms.

i've created a basic test app, and created a stripped down page of html. the
html has a single form.

i get the following error:
fname = main <<<< the app can find the frame from the XPath...

Traceback (most recent call last):
File "./axess.py", line 90, in ?
br.select_form(name = "main") <<<<< app is dying!!!
File "build/bdist.linux-i686/egg/mechanize/_mechanize.py", line 354, in
select_form
mechanize._mechanize.BrowserStateError: not viewing HTML
any thoughts/ideas/comments will be useful!!
thanks

-bruce
test code
---------------------------
import re
import libxml2dom
import urllib
import urllib2
import sys, string
#import numarray
import httplib
from mechanize import Browser, RobustFactory
import mechanize
from BeautifulSoup import *

########################
#
# Parsing App Information
########################


# datafile
tfile = open("stanford.dat", 'wr+')

cj = mechanize.CookieJar()
br = Browser()
if __name__ == "__main__":
# main app
#----------------------------
# start trying to get the stanford pages
cj = mechanize.CookieJar()
# br = Browser(factory=RobustFactory())
br = Browser()

fh = open('axess1.dat')
s = fh.read()
fh.close()
br.open("file:///home/test/axess1.dat")
# br.open(s)

print "foo"

# particular cookiejar)
br.set_cookiejar(cj)

response = br.response() # this is a copy of response

fnamepath = "/html/body[@class='PSPAGE']/form[1]/attribute::name"

s = response.read()
print response.read()
d = libxml2dom.parseString(s, html=1)
ff = d.xpath(fnamepath)
fname = ff[0].nodeValue
print "fname = ",fname
br.select_form(name = "main")

print "ssssss"
sys.exit()

test html
---------------------------
<html lang='en'>
<head>
<title>View Schedule of Classes</title>
</head>
<body class='PSPAGE' >
<br>
<form name="main" method="post" action=
"/servlets/iclientservlet/a2k_prd/?ICType=Panel&amp;Menu=SA_LEARNER_SERVICES
&amp;Market=GBL&amp;PanelGroupName=CLASS_SEARCH "
autocomplete="off" id="main">
</form>
</body>
</html>

hi john...

this is in regards to the web/parsing/factory/beautifulsoup....

to reiterate, i have python 2.4, mechanize, browser, beatifulsoup installed.
i have the latest mech from svn.

i'm getting the same err as reported by john t. the code/err follows.. (i
can resend the test html if you need)
any thoughts/pointers/etc would be helpful...

thanks

-bruce

test code
#! /usr/bin/env python
#test python script
import re
import libxml2dom
import urllib
import urllib2
import sys, string
#import numarray
import httplib
from mechanize import Browser, RobustFactory
import mechanize
import BeautifulSoup

########################
#
# Parsing App Information
########################


# datafile
tfile = open("stanford.dat", 'wr+')

cj = mechanize.CookieJar()
br = Browser()
if __name__ == "__main__":
# main app
#----------------------------
# start trying to get the stanford pages
cj = mechanize.CookieJar()
br = Browser(factory=RobustFactory())

fh = open('axess.dat')
s = fh.read()
fh.close()
br.open("file:///home/test/axess.dat")
Jul 10 '06 #1
0 2415

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bruce | last post by:
hi... it appears that i'm running into a possible problem with mechanize/browser/python rgarding the "select_form" method. i've tried the following and get the error listed: br.select_form(nr...
2
by: Kowalski | last post by:
from mechanize import Browser br = Browser() br.open("http://www.google.com") #example for form in br.forms(): print form br.select_form(name="f") br = "Blah"
12
by: John | last post by:
I have to write a spyder for a webpage that uses html + javascript. I had it written using mechanize but the authors of the webpage now use a lot of javascript. Mechanize can no longer do the job....
2
by: Patrick C | last post by:
I'm trying to learn the basics of the mechanize module and i'm very very new to programming. Does anyone know of some good places to learn the very basics, say with some examples as well? I found...
1
numberwhun
by: numberwhun | last post by:
I am having an issue with understanding something in the WWW::Mechanize module. I have a website which I want to download a whole plethora of pdf files from. It is a site that I have paid to access...
0
by: bruce | last post by:
i'm getting the following error: mechanize._response.httperror_seek_wrapper: HTTP Error 500: i'm running python 5.1 and mechanize 0.1.7b I have no idea as to what I have to...
1
by: Neal Becker | last post by:
I'm trying to use mechanize to read for a M$ mail server. I can get past the login page OK using: import mechanize b = mechanize.Browser() b.open...
2
by: Rex | last post by:
Hello, I am working on an academic research project where I need to log in to a website (www.lexis.com) over HTTPS and execute a bunch of queries to gather a data set. I just discovered the...
0
by: trihaitran | last post by:
I am trying to write a web scraper and am having trouble accessing pages that require authentication. I am attempting to utilise the mechanize library, but am having difficulties. The site I am...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.