So können Sie die HTML-Datentabelle mit Zeichen und X-Y-Koordinaten analysieren und korrekt rendern

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: So können Sie die HTML-Datentabelle mit Zeichen und X-Y-Koordinaten analysieren und korrekt rendern

by Anonymous » 22 May 2025, 12:29

Hier ist die Problemanweisung: Verwenden Sie einen Link zu einem Google -Dokument und drucken Sie die Symbole gemäß X- und Y -Koordinaten im Dokument. In der Einschätzung sind zwei Links von Google Doc enthalten:
Dies ist ein "f":
https://docs.google.com/document/d/e/e/ ... spoxcziv3y. Geheime Nachricht:
https://docs.google.com/document/d/e/e/ ... _defeated/
Ich ran den Code, der leichter zu verstehen ist, und kopieren Sie die Ausgabe. html5lib "In Ihrem Terminal als Antwort auf die anfängliche Fehlermeldung. Ich spreche auch nicht fließend, alle Loops hier vollständig zu verstehen.

Code: Select all

import pandas as pd
from bs4 import BeautifulSoup

def getTableDataSorted(url):
tableData = pd.read_html(url, header=0, flavor='bs4')
return tableData[0].sort_values(by=["y-coordinate","x-coordinate"], ignore_index=True)

def printData(tableData):
xcoord = tableData['x-coordinate']
ycoord = tableData['y-coordinate']
char = tableData['Character']

for i in range(0, len(ycoord)):
if (i != 0) and (xcoord[i] - xcoord[i - 1] != 1):
# empty spaces
print(" " * int((xcoord[i]) - (xcoord[i - 1]) - 1), end='')
if (i !=0) and (ycoord[i] != (ycoord[i - 1])):
# new line
print('\r')
print (char[i], end='')
print('\n')

tableData = getTableDataSorted("https://docs.google.com/document/d/e/2PACX-1vRMx5YQlZNa3ra8dYYxmv-QIQ3YJe8tbI3kqcuC7lQiZm-CSEznKfN_HYNSpoXcZIV3Y_O3YoUB1ecq/pub")
printData(tableData)
print(tableData)

< /code>
Hier ist die Terminalausgabe: < /p>
█
█▀▀
█▀▀▀
< /code>
   x-coordinate Character  y-coordinate
0             0         █             0
1             0         █             1
2             1         ▀             1
3             2         ▀             1
4             0         █             2
5             1         ▀             2
6             2         ▀             2
7             3         ▀             2
< /code>
Das erwartete Ergebnis war: < /p>
█▀▀▀
█▀▀
█
< /code>
Statt█
█▀▀
█▀▀▀

Top