Tried to get number by:
soop = BeautifulSoup(page.content, 'html.parser')
span = soop.find_all('span', class_='tw-animated-number tw-animated-number--monospaced')
print(span)
Got output:
[]
How to get the number?
Tried to get number by:
soop = BeautifulSoup(page.content, 'html.parser')
span = soop.find_all('span', class_='tw-animated-number tw-animated-number--monospaced')
print(span)
Got output:
[]
How to get the number?
The data is loaded dynamically from another URL. To get actual number of viewers on this channel, you can try this script:
import requests
from bs4 import BeautifulSoup
username = 'f1nn5ter'
url = 'https://gql.twitch.tv/gql#origin=twilight'
data = "[{\"operationName\":\"ChannelRoot_SocialMediaSpace\",\"variables\":{\"channelLogin\":\""+username+"\"},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"3cc9b2fc1ce60c0d0bd271e795e6c9d0baef0d7cb8a0f130c5311f4d045157da\"}}},{\"operationName\":\"StreamMetadata\",\"variables\":{\"channelLogin\":\""+username+"\"},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"1c719a40e481453e5c48d9bb585d971b8b372f8ebb105b17076722264dfa5b3e\"}}},{\"operationName\":\"UseViewCount\",\"variables\":{\"channelLogin\":\""+username+"\"},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"00b11c9c428f79ae228f30080a06ffd8226a1f068d6f52fbc057cbde66e994c2\"}}},{\"operationName\":\"UseLiveBroadcast\",\"variables\":{\"channelLogin\":\""+username+"\"},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"5ab2aee4bf1e768b9dc9020a9ae7ccf6f30f78b0a91d5dad504b29df4762c08a\"}}},{\"operationName\":\"Drops_ChannelDrops_User\",\"variables\":{\"login\":\""+username+"\",\"isLoggedIn\":false},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"f309b1d517d288074d50d96512059857cc67d8905d1379e414d70f7b981f2618\"}}},{\"operationName\":\"RealtimeStreamTagList\",\"variables\":{\"channelLogin\":\""+username+"\"},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"9d952e4aacd4f8bb9f159bd4d5886d72c398007249a8b09e604a651fc2f8ac17\"}}}]"
headers = {
'Client-Id': 'kimne78kx3ncx6brgo4mv6wki5h1ko'
}
def traverse(d):
if isinstance(d, dict):
for k, v in d.items():
if k == 'viewersCount':
yield v
return
yield from traverse(v)
elif isinstance(d, list):
for v in d:
yield from traverse(v)
d = requests.post(url, headers=headers, data=data).json()
print(next(traverse(d)))
Prints:
3722