请求返回解码的文本

时间:2019-04-05 12:51:19

标签: python json request

我是python网络抓取中的超级新手,需要您的帮助。我正在尝试使用request.get方法从下注网站中刮取实时赔率。到目前为止,我的代码是:

import requests
from bs4 import BeautifulSoup
import brotli
import json

headers = {
    'Referer': 'https://www.goalbetint.com/login/livebet/index.php',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36',
}

params = (
    ('a', 'live'),
    ('eid', '02H43X41251964'),
    ('dt', 's'),
    ('lang', 'GR'),
    ('r', '897947'),
    ('lot', '211'),
    ('dtp', 'jsonp'),
    ('callback', 'jQuery331043529761295563874_1554465530923'),
    ('_', '1554465530948'),
)


r1 = requests.get('https://livedata4.goalbetservices.com:5443/LB_RemoteLiveFeeders/RemoteLiveBet3XML.HTML5.php', headers=headers, params=params)

r1.text的一部分是这样的:

GameIsVisible":"1","CP":"9","Columns":"0","Mainbet":"0","UsePlayerNames":"0","NEN":"Goal\\/No goal"},"R":[{"attr":{"RID":"02H43X41251964G30-goal","RV":"1","N":"Goal","O0":"4.00","NEN":"Goal"}},{"attr":{"RID":"02H43X41251964G30-nogoal","RV":"1","N":"No Goal","O0":"1.22","NEN":"No Goal"}}]},{"attr":{"GameID":"02H43X41251964G1108","N":"Goal\\/No goal \\u03b4\\u03b5\\u03cd\\u03c4\\u03b5\\u03c1\\u03bf\\u03c5 \\u03b7\\u03bc\\u03b9\\u03c7\\u03c1\\u03cc\\u03bd\\u03bf

那没关系,因为我在“ 1.22”的某个地方出现了奇数,但我想得到\\u03b4\\u03b5\\u03cd\\u03c4\\u03b5\\u03c1\\u03bf\\u03c5 \\u03b7\\u03bc\\u03b9\\u03c7\\u03c1\\u03cc\\u03bd\\u03bf部分

被解码或类似的东西。这部分可能是指文本。如何将响应解码和/或存储在字典中?

谢谢!

1 个答案:

答案 0 :(得分:0)

它不需要解码:它是UTF-8,这是Python的默认设置。只需打印出值即可。您看到反斜杠的原因是您正在打印出原始数据结构。

例如:

>>> a = """Goal\/No goal \u03b4\u03b5\u03cd\u03c4\u03b5\u03c1\u03bf\u03c5 \u03b7\u03bc\u03b9\u03c7\u03c1\u03cc\u03bd\u03bf"""
>>> a
'Goal\\/No goal δεύτερου ημιχρόνο'