Thursday, December 5, 2013

Python / JavaScript gurus - I need some assistance...

Python / JavaScript gurus - I need some assistance... Register Help Remember Me? TechExams.net IT Certification Forums WGU What's New Today's Posts Forum Actions Mark Forums Read Advanced Search Forum General Off-Topic Python / JavaScript gurus - I need some assistance... + Reply to Thread Results 1 to 14 of 14 Thread: Python / JavaScript gurus - I need some assistance... Thread Tools Show Printable Version Subscribe to this Thread… YFZblu YFZblu is offline Senior Member YFZblu's Avatar Join Date Nov 2011 Posts 1,012
Certifications A+, Network+, Security+, CCNA, CCNA: Security, GSEC, GCIH 12-03-2013 05:51 PM #1 Default Python / JavaScript 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?
Attached Images Attached Images File Type: jpg TechExamsSearch.jpg? (31.3 KB, 20 views)
Last edited by YFZblu; 12-03-2013 at 05:54 PM.
Currently Reading: Violent Python
Reply With Quote Quote  
Login/register to remove this advertisement. CarlSaiyed CarlSaiyed is offline Achieve excellence daily Join Date May 2012 Location Washington State Posts 713
Certifications CCNA, CCENT, Security+, CIW JavaScript Specialist, WFA, A+, MTA DB, Soft Dev, Web Dev, 70-461 12-03-2013 05:58 PM #2
in C# this is e.Response.BodyString - do you have a similar property in your response object?
Experience is earned.
Reply With Quote Quote   YFZblu YFZblu is offline Senior Member YFZblu's Avatar Join Date Nov 2011 Posts 1,012
Certifications A+, Network+, Security+, CCNA, CCNA: Security, GSEC, GCIH 12-03-2013 06:06 PM #3
[ObjectName].content() is how the requests module would handle that in Python, if I'm interpreting your question correctly.
Currently Reading: Violent Python
Reply With Quote Quote   CarlSaiyed CarlSaiyed is offline Achieve excellence daily Join Date May 2012 Location Washington State Posts 713
Certifications CCNA, CCENT, Security+, CIW JavaScript Specialist, WFA, A+, MTA DB, Soft Dev, Web Dev, 70-461 12-03-2013 06:29 PM #4
Try [ObjectName].text
Experience is earned.
Reply With Quote Quote   YFZblu YFZblu is offline Senior Member YFZblu's Avatar Join Date Nov 2011 Posts 1,012
Certifications A+, Network+, Security+, CCNA, CCNA: Security, GSEC, GCIH 12-03-2013 07:50 PM #5
.text produces the same result unfortunately
Currently Reading: Violent Python
Reply With Quote Quote   CarlSaiyed CarlSaiyed is offline Achieve excellence daily Join Date May 2012 Location Washington State Posts 713
Certifications CCNA, CCENT, Security+, CIW JavaScript Specialist, WFA, A+, MTA DB, Soft Dev, Web Dev, 70-461 12-03-2013 08:38 PM #6
Maybe I misunderstood - if you cannot view the value you need in source code - where is it stored - JSON or ? Try examining the traffic with Fiddler.
Experience is earned.
Reply With Quote Quote   YFZblu YFZblu is offline Senior Member YFZblu's Avatar Join Date Nov 2011 Posts 1,012
Certifications A+, Network+, Security+, CCNA, CCNA: Security, GSEC, GCIH 12-03-2013 08:59 PM #7
Yeah it looks like this page uses the KnockoutJS library, and JSON. I'm currently reimaging my primary box at home with Windows 8.1, I'll post my Fiddler findings in a bit.
Currently Reading: Violent Python
Reply With Quote Quote   YFZblu YFZblu is offline Senior Member YFZblu's Avatar Join Date Nov 2011 Posts 1,012
Certifications A+, Network+, Security+, CCNA, CCNA: Security, GSEC, GCIH 12-03-2013 10:16 PM #8
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 Python
Reply With Quote Quote   YFZblu YFZblu is offline Senior Member YFZblu's Avatar Join Date Nov 2011 Posts 1,012
Certifications A+, Network+, Security+, CCNA, CCNA: Security, GSEC, GCIH 12-03-2013 10:20 PM #9
It looks like Python 2.7 contains a standard json library, I'm going to try to use that with urllib2 to parse this information out. Thanks for the assistance I'll post my results.
Currently Reading: Violent Python
Reply With Quote Quote   YFZblu YFZblu is offline Senior Member YFZblu's Avatar Join Date Nov 2011 Posts 1,012
Certifications A+, Network+, Security+, CCNA, CCNA: Security, GSEC, GCIH 12-03-2013 11:57 PM #10
So, I'm still confused - Even if it's formatted in JSON, shouldn't the results still be in the source code of the page as a key/value pair or something, just formatted to follow the rules of JSON?

Or would it be normal to store it in some type of variable, the value of which is presented to the User when in the DOM environment? If this is the case, I'm still stuck on how to use Python to present this value to the User.
Currently Reading: Violent Python
Reply With Quote Quote   CarlSaiyed CarlSaiyed is offline Achieve excellence daily Join Date May 2012 Location Washington State Posts 713
Certifications CCNA, CCENT, Security+, CIW JavaScript Specialist, WFA, A+, MTA DB, Soft Dev, Web Dev, 70-461 Yesterday 01:09 AM #11
import 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.
Reply With Quote Quote   YFZblu YFZblu is offline Senior Member YFZblu's Avatar Join Date Nov 2011 Posts 1,012
Certifications A+, Network+, Security+, CCNA, CCNA: Security, GSEC, GCIH Yesterday 01:17 AM #12
Thank you - I'll run through your link
Currently Reading: Violent Python
Reply With Quote Quote   CarlSaiyed CarlSaiyed is offline Achieve excellence daily Join Date May 2012 Location Washington State Posts 713
Certifications CCNA, CCENT, Security+, CIW JavaScript Specialist, WFA, A+, MTA DB, Soft Dev, Web Dev, 70-461 Yesterday 01:20 AM #13
I think the code i posted will get you pretty close
Experience is earned.
Reply With Quote Quote   CarlSaiyed CarlSaiyed is offline Achieve excellence daily Join Date May 2012 Location Washington State Posts 713
Certifications CCNA, CCENT, Security+, CIW JavaScript Specialist, WFA, A+, MTA DB, Soft Dev, Web Dev, 70-461 Yesterday 06:21 AM #14
So how did it turn out?
Experience is earned.
Reply With Quote Quote   + Reply to Thread « Previous Thread|Next Thread »
Social Networking & Bookmarks Bookmarks Submit to Digg Digg Submit to del.icio.us del.icio.us Submit to StumbleUpon StumbleUpon Submit to Google Google Tweet CompTIA Cisco Microsoft CWNP InfoSec Practice Exams Forums Blogs
Watch free videos online
Subnet Calculator Netpict Online Degrees Exam Vouchers Free Magazines Topsites
Certification Kits
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