Q:

Parse the DOM like Javascript using BeautifulSoup

I have a sample HTML in a variable html_doc like this :     
html_doc =  """<table class="sample">
        <tbody>
        <tr class="title"><td colspan="2">Info</td></tr>
        <tr>
        <td class="light">Time</td>
        <td>01/01/1970, 00:00:00</td>
        </tr>
        <td class="highlight">URL</td>
        <td>https://test.com</td>
        </tr>
        </tbody>
        </table>"""

Using Javascript its pretty straightforward if I want to parse the DOM. But if I want to grab ONLY the URL (https://test.com) and Time (01/01/1970, 00:00:00) in 2 different variables from the <td> tag above, how can I do it if there is no class name associated with it.
My test.py file
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc,'html.parser')
test = soup.find_all("td")
print(test)

A:

You can try using regular expression to get the url
from bs4 import BeautifulSoup
import re
soup = BeautifulSoup(html_doc,'html.parser')
test = soup.find_all("td")
for tag in test:
    urls = re.match('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', tag.text)
    time = re.match('[0-9/:, ]+',tag.text)
    if urls!= None:
        print(urls.group(0))
    if time!= None:
        print(time.group(0))

Output

01/01/1970, 00:00:00
https://test.com

