小编Adi*_*mar的帖子

Trimming the outputs in python

I made something which gets the time from https://time.is/ and shows the time. I used BeautifulSoup and urllib.request.

But I want to trim the output. I'm getting this as output and I want to remove the code part.

<div id="twd">07:29:26</div>
Run Code Online (Sandbox Code Playgroud)

Program File:

import urllib.request
from bs4 import BeautifulSoup

url = 'https://time.is/'
hdr = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)' }

req = urllib.request.Request(url, headers=hdr)
res = urllib.request.urlopen(req)
soup = BeautifulSoup(res, 'html.parser')
string = soup.find(id='twd')
print(string)
Run Code Online (Sandbox Code Playgroud)

How can …

python beautifulsoup python-3.x

3
推荐指数
1
解决办法
42
查看次数

标签 统计

beautifulsoup ×1

python ×1

python-3.x ×1