After sending a python HTTP request, it's response (data) has a html page which has many blocks of the ABCD . Here is one snippet
<tr>
<td class="success"></td>
<td class="truncate">ABCD</td>
<td>12/18/2018 21:45</td>
<td>12/18/2018 21:46</td>
<td>10</td>
<td>10</td>
<td>100.0</td>
<td><span class="label success">Success</span></td>
<td>SMS</td>
<td>
<a data-id="134717" class="btn" title="Go">View</a>
</td>
</tr>
I need to retrieve the most recent data-id for ABCD (in this case 134717, and this number is dynamic). Also note there are many of those ABCD's with different dates, I want the most recent .
I can do it using regular expression and going through line by line. But I think it is better to do it with with BeautifulSoup.
I tried this it finds all ABCDs but I dont know how to get the most recent one :
soup = BeautifulSoup(data, "html.parser")
for i in soup.select("td.truncate"):
#print(i.text)
if i.text == "ABCD":
print ("Got it ", i.text)
id1 = soup.select_one("a.data-id")
print (id1)
parsed_url1 = urlparse(id1)