Jump to content

paulm

Members
  • Posts

    24
  • Joined

  • Last visited

Everything posted by paulm

  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.
  15. Not submitting forms to server or db, just browser-based program.
  16. Thanks, so unless using setInterval, I need to track how many forms completed in order to fire new form. Possible to do this in cookie session or HTML5 local storage?
  17. Thanks, last post revised as form hidden onClick now. My overall goal is to keep coding appearing and disappearing text and forms in a sequential fashion. set/clearInterval is key, but I'm wondering if there is a better programmatic way rather than setting each form or text with increasing ms in setInterval. Like: after each clearInterval, then display the new form or text.
  18. Thanks Hadien for clearInterval bit; that indeed stops loop. Using davej's solution for message for now; hoping to get your object approach working, to compare. What's the best way to fire new text or form (make appear) only after a previous clearInterval sequence? I can do this by increasing the ms in each setInterval, but thinking there must be a programmatic way?
  19. "undefined" in console, after radio button click. var Radio1 = {"income": {"current": null,"yes": "You said yes","no": "You said no"}}function output1(val) {Radio1.income.current = val;document.getElementById("start").innerHTML = Radio1.income[Radio1.income.current];}
  20. Cool, got your code partially working...but just writes "yes" or "no" to page, not the message (You said yes, etc): var Radio1 = {"income": {"current": null,"yes": "You said yes","no": "You said no" }}function output1(val) {Radio1.income.current = val;document.getElementById("start").innerHTML = Radio1.income.current.value;} And this is what I mean by my program starting over after radio form submit: the setInterval part that precedes form starts again. I don't want it to. I want to keep giving user more forms and messages (after the radio form) without the whole program starting over. Thanks for direction: var start = ["First greeting", "Second greeting" ];var counter = 0; var elem2 = document.getElementById("start");setInterval(change2, 1000);function change2() {elem2.innerHTML = start[counter]; counter++;if(counter >= start.length) { counter = 1; } }
  21. Thanks Davej, that makes it work, although I'm hoping to learn how to access that submitted value, define in variable, use in conditional, etc. Still don't see how to do that. Hadien thanks for explanation of node behavior. I was under impression it's favorable to create DOM element dynamically. But I guess not always. Either the "current": null or the following was throwing "null" error in console, when I tried bring it your example together: document.getElementById("start").innerHTML = Radio1.income.current.value; This JS text program I'm making uses several setInterval and setTimeout...now, after radio form submit, the whole program is refreshing and looping through again...how to prevent that so I can carry on with more forms, user input, etc, without the whole thing starting over every time I get some user input? Thanks.
  22. Thanks Hadien, that dusted off some cobwebs...now stumbling on working with submitted value. Have a look please: <form name = "Radio1" action="">Yes <input type="radio" name="income" value="yes1" onClick="output1(this.form)">No <input type = "radio" name="income" value="no1" onClick="output1(this.form)"></form><script>function output1(income) {var select = document.getElementsByName("income");for (var i = 0; i < select.length; i++) {} // unsure where incrementing fits w/ finding form valuevar choice = (select.value == "yes1") ? "You clicked yes" : "You clicked no"; //trying to append value to name elementvar par = document.createElement("p"); var parText = document.createTextNode(choice); par.appendChild(parText);document.body.appendChild(par);}
  23. No errors in console, but no alert either. Need to use clicked radio button values. Thanks for help. Btw the new forum looks great guys. <div id="hidForm1" style="display:none;"> //hidden form that pops up 5000ms<form name = "Radio1">Yes <input type="radio" name="income" value="yes1" onClick="this.form.submit()">No <input type="radio" name="income" value="no1" onClick="this.form.submit()"></form></div><script>function showForm() {document.getElementById("hidForm1").style.display = "block"; //working}setTimeout("showForm()", 5000);var choice = document.getElementsByName("income");for (var i = 0; i < choice.length; i++) {if (choice[i].checked) {alert(choice[i].value); //not working } }
×
×
  • Create New...