【发布时间】:2020-02-11 19:48:57
【问题描述】:
在 python 中,我正在阅读一个包含很多东西的 html 页面内容。 为此,我通过这种方式将网页作为字符串读取:
url = 'https://myurl.com/'
reqq = req.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
reddit_file = req.urlopen(reqq)
reddit_data = reddit_file.read().decode('utf-8')
如果我打印 reddit_data 我可以正确看到整个 html 内容。
现在,里面有一个像 json 这样的结构,我想从中读取并提取一些字段。
结构下方:
"dealDetails" : {
"f240141a" : {
"egressUrl" : "https://ccc.com",
"title" : "ZZZ",
"type" : "ghi",
},
"5f9ab246" : {
"egressUrl" : "https://www.bbb.com/",
"title" : "YYY",
"type" : "def",
},
"2bf6723b" : {
"egressUrl" : "https://www.aaa.com//",
"title" : "XXX",
"type" : "abc",
},
}
我想要做的是:找到dealDetails 字段,然后为每个f240141a 5f9ab246 2bf6723b
获取 egressURL、标题和类型值。
谢谢
【问题讨论】:
-
你能发布完整的
script标签吗?