Jump to content

paulm

Members
  • Posts

    24
  • Joined

  • Last visited

paulm's Achievements

Newbie

Newbie (1/7)

1

Reputation

  1. I got phantomjs working to retrieve html from https urls by: path-to/phantom.js --ssl-protocol=any /path-to/script.js in case it helps someone.
  2. Just happened on phantomjs, which seems the right direction to get html obfuscated by JavaScript. Phantomjs script is working with w3schools.invisionzone.com as url, but not with Google Trends url. I'm showing the output of the troubleshooting script here; thanks for help. "headers": [ { "name": "User-Agent", "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36" }, { "name": "Accept", "value": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" } ], "id": 1, "method": "GET", "time": "2016-08-07T14:02:34.247Z", "url": "http://www.google.com/trends/home/m/US" }Request { "headers": [ { "name": "User-Agent", "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36" }, { "name": "Accept", "value": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" } ], "id": 2, "method": "GET", "time": "2016-08-07T14:02:34.473Z", "url": "https://www.google.com/trends/home/m/US" }Unable to access network
  3. Viewing Page Source, and downloading url with wget both show this Google Trends page without the "Stories Trending Now" list, that is visible in Developer Console: md-list.md-list-block.ng-scope Searching on this topic points to JavaScript hiding elements of DOM. So how to download this section of the page? Thanks in advance for guidance.
  4. I have a timer trigger function... function createTimeDrivenTriggers() { // Trigger every 1 hour. ScriptApp.newTrigger('createDoc') .timeBased() .everyHours(1) .create();} that calls createDoc function, which inserts JSON to paragraph: parasub = body.insertParagraph(3, "Subscribers: " + viewsb); paraview = body.insertParagraph(4, "Total Views: " + views); So every hour I'm getting 2 new paragraphs/lines added to the doc. Instead, I need to have the previous paragraphs cleared, so that only the latest JSON data shows. I'm trying to use clear() function, but if I put it above parasub/paraview, clear() is undefined, and if I put it below parasub/paraview, the data is deleted. That all makes sense. So how to clear previous parasub/paraview content before inserting new data? parasub.clear(); paraview.clear();
  5. paulm

    JSON Help

    Thanks, that makes the array-object model clear. One question though, how do the appended objects under your var = item know that they're coming from array "items": [ ? I'm not seeing recursion connecting them. data.items = new Array;var item = new Object;
  6. paulm

    JSON Help

    If there were a closing } before statistics, then we'd get viewCount by data.items[1].statistics.viewCount right? Indexing with braces seems helpful to access name lists, etc. But because all these key/value pairs are unique (not list of names), why is group after semantics nested?
  7. paulm

    JSON Help

    Made a lot of progress, thanks. I compared my data output to the docs, that it seems that my JSON code is complete? I followed your clue about another object on top level and added nested parameters in url: fields=items(statistics(viewCount, subscriberCount)) which gave me what I needed. Then, I tried your data.items[0].statistics.viewCount defined in a variable, and that also works. I'm seeing the nested structure better: [0] pertains to all keys in items because they're all in the first level of items.
  8. paulm

    JSON Help

    Hi, first I'll show what kind of works, then what's not working at all. I'm using Google API app script, pretty much JavaScript, to insert text/stats from a YouTube url, inside a Google Doc. Running this code from script editor... function createDoc() { var doc = DocumentApp.getActiveDocument(); var body = doc.getBody(); var url = "a_long_url_with_auth_key"; var response = UrlFetchApp.fetch(url); body.insertParagraph(4, response); } ...inserts this data in new paragraph. Note viewCount key/pair...that's what I need to isolate (as View Count : #) {"kind": "youtube#channelListResponse","etag": ""sGDdEsjSJ// some account stuff"pageInfo": { "totalResults": 1, "resultsPerPage": 1},"items": [ { "kind": "youtube#channel", "etag": ""sGDdEsjSJ_// account stuff "id": "UCOa9jWlm8SIzlcERzZso0WA", "statistics": { "viewCount": "612280", "commentCount": "0", "subscriberCount": "1243", "hiddenSubscriberCount": false, "videoCount": "435" } }]} So I add JSON... function createDoc() { var doc = DocumentApp.getActiveDocument(); var body = doc.getBody(); var url = "this_all_works"; var response = UrlFetchApp.fetch(url); var data = JSON.parse(response.getContentText()); body.insertParagraph(4, data); } which inserts only this in new paragraph (not all the key/value pairs above): [object Object] and appending viewCount: body.insertParagraph(4, data.viewCount); shows undefined So then I try a for loop, from which I can get no information to print to paragraph, nor even Logger.log (console). Logger.log does print logs from variables outside the loop. It's just not working inside the loop. So I'm not getting any feedback at all from this for loop. function createDoc() { var doc = DocumentApp.getActiveDocument(); var body = doc.getBody(); var url = "this_all_works"; var response = UrlFetchApp.fetch(url); var data = JSON.parse(response.getContentText()); for (var i = 0; i < data.length; i++){ var obj = data[i]; Logger.log(obj); //also trying obj.viewCount v v body.insertParagraph(4, obj); } } Seems to me something's breaking down at JSON level. Along with API docs, I've read the section on JSON. Thanks in advance for help.
  9. Thanks, display: none. Now I'm going to try to get different canvas image sprites to display onClick. I'll be back no doubt. Thanks again.
  10. Thanks davej. The images need to display only after onclick though. As it stands, both images display until either yes or no is selected. Advice appreciated.
  11. How to display different .png images with yes or no form selection? Like dragon image for yes and boy for no. Thanks. <form name = "Radio1" action="">Yes <input type="radio" id= "yes" name="income" value="yes" onClick="output1('Yes'); showImage();">No <input type = "radio" id="no" name="income" value="no" onClick="output1('No');showImage();"></form> var yesField = document.getElementById('yes');var noField = document.getElementById('no');var imageDragon = document.getElementById('dragonImage'); // .src defined previouslyvar imageBoy = document.getElementById('hero'); //.src defined previouslyfunction showImage() {if ('yesField {document.getElementById('imageDragon').style.display = 'block'; }else {document.get.ElementById('imageBoy').style.display = 'block'; }}
  12. Thanks again, seems <fieldset> is used to group like-fields within a form; draws a box around the fields. Disable is an option. Seems this could be useful in a long form with field set data you want to process without submitting the whole form. In the meantime attaching function to onClick method in a form seems to give a lot of functionality even when not submitting data to server/db.
  13. When trying radio buttons without form, I was able to select multiple buttons, which was a problem. Else yes I really don't need forms for this per se.
  14. wasn't aware there was another way to interact with user.
×
×
  • Create New...