奇怪的json值urllib python

2024-04-18 05:56:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试操作此站点的动态JSON:

http://esaj.tjsc.jus.br/cposgtj/imagemCaptcha.do

它有3个元素,imagem,一个base64,labelValorCaptcha,只是一条消息,和uuidCaptcha,一个通过参数传递的值,在下面的链接中播放声音:

http://esaj.tjsc.jus.br/cposgtj/somCaptcha.do?timestamp=1455996420264&uuidCaptcha=sajcaptcha_e7b072e1fce5493cbdc46c9e4738ab8a

当我通过浏览器进入第一个站点并在第二个链接中输入相等(“…uuidCaptcha=”)后的uuidCaptha时,声音正常播放。我编写了一个简单的代码来捕捉这些元素。你知道吗

import urllib, json
url = "http://esaj.tjsc.jus.br/cposgtj/imagemCaptcha.do"
response = urllib.urlopen(url)
data = json.loads(response.read())
urlSound = "http://esaj.tjsc.jus.br/cposgtj/somCaptcha.do?timestamp=1455996420264&uuidCaptcha="
print urlSound + data['uuidCaptcha']

但我不知道发生了什么,uuidCaptcha的捕获值不起作用。打开错误网页。你知道吗

有人知道吗? 谢谢!你知道吗


Tags: br声音http元素站点链接dotimestamp
2条回答

这对我很有用。你知道吗

$ cat a.py
#!/usr/bin/env python
# encoding: utf-8
import urllib, json


url = "http://esaj.tjsc.jus.br/cposgtj/imagemCaptcha.do"
response = urllib.urlopen(url)
data = json.loads(response.read())
urlSound = "http://esaj.tjsc.jus.br/cposgtj/somCaptcha.do?timestamp=1455996420264&uuidCaptcha="
print urlSound + data['uuidCaptcha']

$ python a.py
http://esaj.tjsc.jus.br/cposgtj/somCaptcha.do?timestamp=1455996420264&uuidCaptcha=sajcaptcha_efc8d4bc3bdb428eab8370c4e04ab42c

正如我所说的@charlieharding,最好的方法是下载页面并获取JSON值,因为这个JSON是动态的,需要一个打开的web链接才能存在。你知道吗

更多信息here。你知道吗

相关问题 更多 >