Ich bin dabei gerade eine Webseite auszulesen und habe mit guter Unterstützung schon fein meine Tags auslesen können. Ich habe jetzt ein weiteres Problem, was ich nicht mehr deuten kann.
Code: Alles auswählen
# this is the URL to access the history
url = 'https://www.name.de'
# open the URL with urllib2
fileHandle = urllib2.urlopen(url)
# read the result and store in a string
str1 = fileHandle.read()
# Create a beautiful instance with the string
soup = BeautifulSoup(str1)
# Close the connection
fileHandle.close()
# this pattern detects all HTML tags
tagPattern = r"<[a-zA-Z\/][^>]*>"
# allTdsAsList contains something like <td class="std" onclick="...">
# the_data_i'm_interessted_in </td> for all hits (list)
allTdsAsList = soup.findAll('td',{'class' : 'std', 'onclick' : True})
# check if there is at least one singleTdEntryToRemove...
if allTdsAsList != None:
# we iterate over all entries
for singleTdEntry in allTdsAsList:
# at this point we have only one <td> tag here:
# <td class="std" onclick="..."> the_data_i'm_interessted_in </td>
# Our tdEntriesToRemove is the complete <td> tag data
# the result is a list with all entries that can be removed
tdEntriesToRemove = re.findall(str(tagPattern), str(singleTdEntry))
# if we have some entries to remove...
if tdEntriesToRemove != None:
# iterate over every single entry
for singleTdEntryToRemove in tdEntriesToRemove:
print singleTdEntry
print singleTdEntryToRemove
singleTdEntry = singleTdEntry.replace(tagPattern, '')
2. ich will dann mit einer RegExp über die <td> Einträge laufen und nur noch den Nutztext überlassen, dass mache ich mit der Regular Expression. Die funktioniert auch - das habe ich getestet.
3. Ich bekomme immer folgenden Fehler: TypeError: 'NoneType' object is not callable (In der Zeile 37). Ich habe die Print Anweisungen mal vorgesetzt um zu sehen was drin ist. Das sieht soweit gut aus: <td class="std" onclick="function(232);">Payload</td> ist in singleTdEntry drin, soweit gut. Nun will ich das Payload haben und will die HTML Tags entfernen. Das was ich entfernen will steht nun in singleTdEntryToRemove = <td class="std" onclick="function(232);">. Passt alles soweit gut, nur ich kann jetzt mit der Fehlermeldung nichts anfangen. Ich will in der Zeile 37 einfach nur aus dem singleTdEntry die Nutzdaten machen und das HTML entfernen.
Mein googeln zu der Fehlernachricht war nicht richtig erfolgreich und ich konnte meine Ursache nicht ableiten. Wenn ich mir jetzt ein kleines Minimalbeispiel baue und die replace Funktion nutze klappt das so schon, nur hier nicht. Ich finde das Problem aber nicht. Sieht jemand meinen Fehler?
Danke!