Cookielib in Jython
Hi There, I'm trying to run an App I wrote in Python 2.5.2 in Jython 2.2.1 and everything works fine except when I try to import the Standard CPython's cookielib. I know this may sound stupid, I could use an advice here on what's wrong. Thanks in advance, Felipe. Output: Jython 2.2.1 on java1.6.0_07 Type "copyright", "credits" or "license" for more information. >>> import cookielib Traceback (innermost last): File "", line 1, in ? ImportError: no module named cookielib >>> from cookielib import * Traceback (innermost last): File "", line 1, in ? ImportError: no module named cookielib >>> from CookieLib import * Traceback (innermost last): File "", line 1, in ? ImportError: no module named CookieLib -- http://mail.python.org/mailman/listinfo/python-list
Re: Cookielib in Jython
On Oct 6, 10:36 am, [EMAIL PROTECTED] wrote: > On 6 Ott, 13:19, Felipe De Bene <[EMAIL PROTECTED]> wrote: > > > > > Hi There, > > I'm trying to run an App I wrote in Python 2.5.2 in Jython 2.2.1 and > > everything works fine except when I try to import the Standard > > CPython's cookielib. I know this may sound stupid, I could use an > > advice here on what's wrong. Thanks in advance, > > Felipe. > > > Output: > > Jython 2.2.1 on java1.6.0_07 > > Type "copyright", "credits" or "license" for more information.>>> import > > cookielib > > > Traceback (innermost last): > > File "", line 1, in ? > > ImportError: no module named cookielib>>> from cookielib import * > > > Traceback (innermost last): > > File "", line 1, in ? > > ImportError: no module named cookielib>>> from CookieLib import * > > > Traceback (innermost last): > > File "", line 1, in ? > > ImportError: no module named CookieLib > > Obviously, choockielib is not in your jython installation. > If this module is a pure python module and not a wrupper of an > underlying C > module, you could try simple to get is from a CPython installation, > try and > compile it with Jython inside the code. If the module does not use any > feature > of the language introduced after Python 2.2, or other unsupported > modules, > it could work and you can use it inside your program as it was one of > your modules. > > HTH > > FB Thanks that worked :D -- http://mail.python.org/mailman/listinfo/python-list
HTML File Parsing
I'm having problems parsing an HTML file with the following syntax : User ID NameDate and so on whenever I feed the parser with such file I get the error : Traceback (most recent call last): File "C:\Documents and Settings\Administrator\My Documents\workspace \thread\src\parser.py", line 91, in p.parse(thechange) File "C:\Documents and Settings\Administrator\My Documents\workspace \thread\src\parser.py", line 16, in parse self.feed(s) File "C:\Python25\lib\HTMLParser.py", line 110, in feed self.goahead(0) File "C:\Python25\lib\HTMLParser.py", line 152, in goahead k = self.parse_endtag(i) File "C:\Python25\lib\HTMLParser.py", line 316, in parse_endtag self.error("bad end tag: %r" % (rawdata[i:j],)) File "C:\Python25\lib\HTMLParser.py", line 117, in error raise HTMLParseError(message, self.getpos()) HTMLParser.HTMLParseError: bad end tag: "", at line 515, column 45 Googling around I've found a solution to a similar situation, over and over again : http://64.233.169.104/search?q=cache:zOmjwM_sGBcJ:coding.derkeiler.com/pdf/Archive/Python/comp.lang.python/2006-02/msg00026.pdf+CDATA_CONTENT_ELEMENTS&hl=pt-BR&ct=clnk&cd=5&gl=br&client=firefox-a but coding : you can disable proper parsing by setting the CDATA_CONTENT_ELEMENTS attribute on the parser instance, before you start parsing. by default, it is set to CDATA_CONTENT_ELEMENTS = ("script", "style") setting it to an empty tuple disables HTML-compliant handling for these elements: p = HTMLParser() p.CDATA_CONTENT_ELEMENTS = () p.feed(f.read()) didn't solve my problem. I've made a little modification then to HTMLParser.py instead that solved the problem, as follows: original: endtagfind = re.compile('') my version : endtagfind = re.compile('') it worked ok for all the files I needed and also for a different file I also parse using the same library. I know it might sound stupid but I was just wondering if there's a better way of solving that problem than just modifying the standard library. Any clue ? thx in advance, Felipe. -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML File Parsing
On Oct 28, 6:18 pm, Stefan Behnel <[EMAIL PROTECTED]> wrote: > Felipe De Bene wrote: > > I'm having problems parsing anHTMLfile with the following syntax : > > > > > User ID > > Name > BGCOLOR='#c0c0c0'>Date > > and so on > > > whenever I feed the parser with such file I get the error : > > > HTMLParser.HTMLParseError: bad end tag: "", at > > line 515, column 45 > > YourHTMLpage is notHTML, i.e. it is broken. Python's HTMLParser is not made > for parsing brokenHTML. However, you can use the parse of lxml.htmlto fix up > yourHTMLfor you. > > http://codespeak.net/lxml/ > > Stefan Actually i fetch from an application that i thought it should act like this and as I told you, the program is ready to be shipped so rewriting an entire class that has public methods would be a real pain. I really had to find a way to work this out by using the python's parser instead of external libraries. But thanks anyway for the clue, I might start working on a similar project next and this library may be a good and a less painful path. Thanks :D Felipe. -- http://mail.python.org/mailman/listinfo/python-list