Beautifulsoup replacewith

Sockets, TCP/IP, (XML-)RPC und ähnliche Themen gehören in dieses Forum
Antworten
Martu
User
Beiträge: 15
Registriert: Montag 21. Juli 2008, 00:02
Wohnort: nähe Darmstadt

hallo, und wieder ich.
Diesmal hab ich nen Problem mit BeautifulSoup bei dem ich wieder nicht weiterkomme :cry:
mein Code:

Code: Alles auswählen

soup = BeautifulSoup(html_dat)
comment = """
            <tr bgcolor="#484848">
                <td widht="50%" style="border-left-width:2px; border-top-width:2px; border-bottom-width:0px; border-right-width:0px; border-style:solid; border-color:#000000; ">
                    """, autorname,"""
                </td>
                <td width="50%" align="right" style="border-right-width:2px; border-top-width:2px; border-bottom-width:0px; border-left-width:0px; border-style:solid; border-color:#000000; ">
                    """, datetime.datetime.today(),"""
                </td>
            </tr>
            <tr>
                <td colspan="2" bgcolor="#626262" style="border-width:2px; border-style:solid; border-color:#000000; ">
                    """, autortext,"""
                </td>
            </tr>
            <tr height="25px">
            </tr>
            <!--ersetzen-->"""
ersetzen = soup.find(name="<!--", text="ersetzen")
print ersetzen
ersetzen.replaceWith(comment)
html_dat.write(soup)
html_dat.close
die Fehlermeldung:

Code: Alles auswählen

Traceback (most recent call last):
  File "C:\html_seite\vers_2\cgi-bin\gaestebuch.py", line 34, in <module>
    ersetzen.replaceWith(comment)
  File "C:\Python25\lib\BeautifulSoup.py", line 137, in replaceWith
    oldParent.insert(myIndex, replaceWith)
  File "C:\Python25\lib\BeautifulSoup.py", line 195, in insert
    newChild.parent = self
AttributeError: 'tuple' object has no attribute 'parent'
was habe ich da wieder angerichtet? :lol:

mfg. Martu
mfg. Martu
BlackJack

Rate mal an was für ein Objekt der Name `comment` gebunden ist. Falls Du es durch scharfes Hinsehen nicht heraus bekommst, hilft ``print type(comment)`` weiter.
Antworten