Извлечь данные c из urllib - PullRequest
       12

Извлечь данные c из urllib

0 голосов
/ 23 апреля 2020

Привет! Я хочу получить указанный текст c с веб-сайта, используя этот метод, например. songtitle et c.

 import urllib.request, json  with
 urllib.request.urlopen("https://radio.habboland.net/api/nowplaying/habboland")
 as url:
     data = json.loads(url.read().decode())
     print(data)

Есть идеи?

1 Ответ

0 голосов
/ 23 апреля 2020
import urllib.request, json
user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'
url = "https://radio.habboland.net/api/nowplaying/habboland"
headers={'User-Agent':user_agent,}
request=urllib.request.Request(url,None,headers)
with urllib.request.urlopen(request) as req:
    data = json.loads(req.read().decode())
    print(data['now_playing']['song']['title'])

вывод:

Easter Prom Live
...