1
我想從html表中提取一個URL。該URL位於td單元格內的錨標籤內。 的HTML看起來像:使用Beautiful Soup從td元素中提取URL
<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>
這裏是Python代碼,我已經寫了:
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"):
我走過一路具有URL最後的td標籤。我現在如何提取網址?
提前感謝您的時間。
謝謝@Alex大廳 – Ram