gurus - I need some assistance...
Hey all, I have an issue I'm trying to work out in Python. I'm pretty new to programming/scripting, so bear with me on this.
There's a site my team uses quite a bit at work; the Bluecoat Site Review page. This page takes user input in the form of a URL, and then displays that website's categorization according to Bluecoat. It's located here : WebPulse Site Review Request
Anyway, what I want to do is write a command-line script that sends a request to this page in the form of an HTTP POST, and parses the response to display only the site categorization of the website submitted by the User.
In a perfect world my script would receive the response and search the document for a certain string; if found, that string would be printed to standard out. The issue I'm having is that Bluecoat's response does not give the site categorization as a string literal - the response is actually sent back as a variable value. That value is not directly reported back in the source code of the page, only the variable is. And I don't know how to grab the value of this variable with Python to display to the User. Here is the return result as it appears in the source code of the result:
"This page is currently categorized as "
I've been using Python's "Requests" module to make the HTTP request because it seems to have the most elegant syntax; however I'm open to learning/using something else like urllib2 or mechanize if it is more appropriate for this situation. Any ideas?Indeed, it appears to be JSON:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json
Date: Tue, 03 Dec 2013 22:12:08 GMT
Content-Length: 1130
Currently Reading: Violent Pythonimport json
import pprint
data = json.loads([ObjectName].content()) //decode the json into an object you can work with.
pprint(data) //if this looks funny, decode it again with data = json.loads(json.loads([ObjectName].content()))
You should be able to go by name from there
Source: Python accessing data in JSON object - Stack Overflow
Experience is earned. Home Forum Rules Contact UsSupport Us Archive Privacy Statement Top TechExams.net ? 2002 - 2013 - All times are GMT. The time now is 08:32 AM. - CSS version TechExams.Net is not sponsored by, endorsed by or affiliated with Cisco Systems, Inc. Cisco®, Cisco Systems®, CCDA?, CCNA?, CCDP?, CCNP?, CCIE?, CCSI?; the Cisco Systems logo and the CCIE logo are trademarks or registered trademarks of Cisco Systems, Inc. in the United States and certain other countries. All other trademarks, including those of Microsoft, CompTIA, Juniper ISC(2), and CWNP are trademarks of their respective owners.
Powered by vBulletin® Version 4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.0
View the original article here
No comments:
Post a Comment