1
Ich versuche, eine URL aus einer HTML-Tabelle zu extrahieren. Die URL befindet sich innerhalb eines Anchor-Tags in einer Td-Zelle. Die html wie folgt aussieht:Extrahieren einer URL von Td-Element mit Beautiful Soup
<table width="100%" border="0" cellspacing="0" cellpadding="0" name="TabName" id="Tab" class="common-table">
<tr>
<td>Acme Company</a><br/><span class="f-10">07-11-2016</span></td>
<td><span>Vendor</span><br>
<td><a href="http://URL" title="Report Details">Details</a></td>
</tr>
</table>
Hier ist der Code Python ist ich geschrieben habe:
from bs4 import BeautifulSoup
import requests
import re
r = requests.get('http://SourceURL')
soup = BeautifulSoup(r.content,"html.parser")
# Find table
table = soup.find("table",{"class": "common-table"})
# Find all tr rows
tr = table.find_all("tr")
for each_tr in tr:
td = each_tr.find_all('td')
# In each tr rown find each td cell
for each_td in td:
print(each_td.text)
if(each_td.text == "Details"):
ich den ganzen Weg bis zur endgültigen td-Tag durchlaufen, der die URL hat. Wie extrahiere ich jetzt die URL?
Vielen Dank im Voraus für Ihre Zeit.
Danke @ Alex Halle – Ram