L
L
leistolz2016-02-19 23:38:47
Parsing
leistolz, 2016-02-19 23:38:47

How to parse twitch stream title string?

There is a piece of html streamer profile code, you need to parse a string from it.

<!DOCTYPE html>
<html lang='ru' style='overflow: hidden;' xml:lang='ru' xmlns:fb='http://www.facebook.com/2008/fbml' xmlns:og='http://opengraphprotocol.org/schema/' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>Twitch</title>
<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
<meta content='app-id=460177396, app-argument=twitch://open' name='apple-itunes-app'>
<meta content='Twitch' name='description'>
<link href='/favicon.ico' rel='shortcut icon' type='image/x-icon'>
<meta content='general' name='rating'>
<link href='android-app://tv.twitch.android.app/twitch/open?channel=dorofeus' rel='alternate'>
<link href='ios-app://460177396/twitch/channel/dorofeus' rel='alternate'>
<meta content='nfsZd38ZV83T6MdjAsLhwdcQHPT3HkidcTELZkVxE3k' name='google-site-verification'>
<link href='https://plus.google.com/115463106831870703431' rel='publisher'>
<meta content='Twitch' property='og:site_name'>
<meta content='161273083968709' property='fb:app_id'>
<meta content='dorofeus' property='og:title'>
<meta content='Псевдоинтеллектуальный стрим' property='og:description'>
<meta content='https://static-cdn.jtvnw.net/jtv_user_pictures/dorofeus-profile_image-1a23835371d8ff70-600x600.jpeg' property='og:image'>
<meta property='og:url'>
<meta content='video.other' property='og:type'>
<meta content='http://www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?channel=dorofeus&playerType=facebook' property='og:video'>
<meta content='https://www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?channel=dorofeus&playerType=facebook' property='og:video:secure_url'>
<meta content='application/x-shockwave-flash' property='og:video:type'>
<meta content='378' property='og:video:height'>
<meta content='620' property='og:video:width'>

Namely, you need a "Pseudo-intelligent stream" located in this line:
<meta content='Псевдоинтеллектуальный стрим' property='og:description'>

I tried to parse in different ways, but it didn’t work, that is, the name simply wasn’t displayed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D', 2016-02-19
@Denormalization

Twitch has an API https://github.com/justintv/Twitch-API
It pulls out all the info about the streamer and the streamer in JSON format.
In essence:
"I tried to parse in different ways, but it didn't work, that is, the name simply wasn't displayed."
Should we guess the language and platform ourselves?

V
Vladimir Kuts, 2016-02-20
@fox_12

For example - how the search is pulled in python:

import lxml.html

data = """
ваш html код
"""

xmldata = lxml.html.document_fromstring(data)
print xmldata.xpath("//meta[@property='og:description']")[0].get('content')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question