2

I'm trying to manipulate a dynamic JSON from this site:

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

It has 3 elements, imagem, a base64, labelValorCaptcha, just a message, and uuidCaptcha, a value to pass by parameter to play a sound in this link bellow:

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

When I enter in the first site through a browser and put in the second link the uuidCaptha after the equal ("..uuidCaptcha="), the sound plays normally. I wrote a simple code to catch this elements.

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']

But I dont know what's happening, the caught value of the uuidCaptcha doesn't work. Open a error web page.

Someone knows? Thanks!

  • What's the error? What does the print statement output? – Charlie Harding Feb 20 '16 at 20:11
  • Also you probably need to insert the current timestamp: `import time` at the start, then change the definition of urlSound to `urlSound = "http://esaj.tjsc.jus.br/cposgtj/somCaptcha.do?timestamp=" + str(int(time.time())) + "&uuidCaptcha="` The str(int(…)) rounds the timestamp to the nearest second, and then converts it to a string so that it can be used in the URL – Charlie Harding Feb 20 '16 at 20:17
  • @CharlieHarding The print output should be a link that open a sound, like [this](http://esaj.tjsc.jus.br/cposgtj/somCaptcha.do?timestamp=1455996420264&uuidCaptcha=sajcaptcha_407e9a85a31d49588c429cdd4c41bd1d). – Heliaquim Costa Feb 20 '16 at 20:20
  • @CharlieHarding The timestamp is just to prevent cache, doesn't stop the sound be opened. You can put any valid timestamp there. – Heliaquim Costa Feb 20 '16 at 20:32
  • You say that it should output this string, but it doesn't. What does it output: can you paste the error here? It could be that you are simply running Python 3, in which case the print statement should be a function: `print(urlSound + data['uuidCaptcha'])` – Charlie Harding Feb 21 '16 at 11:43
  • @CharlieHarding Theres no error message to paste, just a wrong link formed by urlSound + data['uuidCaptcha']. As I wrote at the end of the question, the output link should play a sound. – Heliaquim Costa Feb 28 '16 at 08:32
  • Could it be because of the user agent of the python fetching script? – Charlie Harding Feb 28 '16 at 11:50
  • @CharlieHarding great! The best way is download the page ang get the values, because this JSON is dynamic and need an opened link to exist (sorry for a late answer) – Heliaquim Costa Mar 18 '16 at 17:49

2 Answers2

0

It works for me.

$ 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
Wanming Zhang
  • 323
  • 1
  • 8
0

As I said @Charlie Harding, the best way is download the page and get the JSON values, because this JSON is dynamic and need an opened web link to exist.

More info here.

Community
  • 1
  • 1