I am trying to extract data from a webpage which requires login.
The following code with
URLfetchapp.fetch(x).getcontentText()
returns the login page, however I want to get the data after login security page. Code to get data from the page is :
function getPTtrack(linksArray){
linksArray = `https://www.blogger.com/about/`;
var ptTracknames = [];
for(var sear in linksArray){
var optoutlink= linksArray[sear].toString().search("Publish your passion");
if(optoutlink!=-1){
var x = linksArray[sear].replace(">.","").replace("<","").replace(">","").toString();
var page = UrlFetchApp.fetch(x).getContentText();
var number = page.match(/<b>(.*)<\/b>/)[1];
Logger.log(number);
ptTracknames.push(number);
}
}
console.log(ptTracknames);
return ptTracknames;
}
But when I run the code to get the data after login to the page. I didn't get the data from next page instead I get the login page html code in console. Can anyone please suggest what code should I use
Related
I have one URL which asks me to " click here to login" then the next page loads.
once the next page loads I need to pass the credential. tried below script but didn't work
document.getElementsByClassName('click_hereTo_login')[0].click();
$( document ).ready(function()
{ if document.location.href=="https://example.com/secondpage"
then {
document.getElementById('id').value="12322";
document.getElementById('password').value="4444";
document.getElementsByClassName('login')[0].click();
}})
First of all your if is not written correctly. It should be:
if (document.location.href=="https://example.com/secondpage"){
document.getElementById('id').value="12322";
document.getElementById('password').value="4444";
document.getElementsByClassName('login')[0].click();
}
The another problem here is, that your script runs from scratch on both pages. If you want to pass data from page to page without backend, you can use either query string or localstorage to store the data somewhere and then access it from another page.
let id = localStorage.getItem('id');
// get the input element
let idInput = document.getElementById('id');
// check if we are one second page
if(idInput) {
document.getElementById('id').value = id;
}
// Save id on login click
document.querySelector('.login').addEventListener('click', () => {
localStorage.setItem('id', 1234);
});
I am beginner in Javascript. I am currentlyworking on a Phonegap app with it. I am stuck in between as I have 4 html pages for signup process, and I have to pass all the html pages input value to single js file as in final all data must be POSTed to server URL and also I have read on many sites that they have recommended using same js file for all the pages of your site to speed up the site. So I have two problems to solve. I searched on many sites but could not find the accurate answer.
I need to pass 4 html page's input value to single js file.
I have to make single js file for both sign-in and sign-up.
My codes for JS page is:
var firstName="";
var lastName="";
var email="";
var password="";
var retypePassword="";
var gender="";
var DOB="";
var institute="";
var course="";
var branch="";
var semester="";
var teachers = [];
function signUpStarting() {
alert(firstName + " "+lastName+" "+email+" "+password+" "+retypePassword+" "+gender+" "+DOB+" "+institute+" "+course+" "+branch+" "+semester+" "+teachers.join(","));
}
function signUp1() {
firstName[0] = $("#first_name").val().trim();
firstName[1] = $("#last_name").val().trim();
email = $("#email").val().trim();
password = $("#password").val();
retypePassword = $("#retype_password").val();
alert(firstName + " "+lastName+" "+email+" "+password+" "+retypePassword);
}
function signUp2() {
gender = $('#gender').find(":selected").text();
DOB = $('#DOB').val();
alert(gender+" "+DOB);
}
function signUp3() {
institute = $('#institute').find(":selected").text();
course = $('#course').find(":selected").text();
branch = $('#branch').find(":selected").text();
semester = $('#semester').find(":selected").text();
alert(institute+" "+course+" "+branch+" "+semester);
}
function signUp4() {
$(":checkbox" ).map(function() {
if($(this).is(':checked')){
teachers.push($('label[for="' + this.id + '"]').text());
}
});
signUpStarting();
}
In html pages I am calling JS functions for each pages:
On first page:
<a onclick="signUp1()" href="register-two.html">continue</a>
On second page:
<a onclick="signUp2()" href="register-three.html">continue</a>
On third page:
<a onclick="signUp3()" href="register-four.html">continue</a>
On fourth page:
<a onclick="signUp4()">continue</a>
On each transaction from one page to next I have set alert in JS, and I am getting alert with accurate values also. But after clicking the continue button from fourth page of html, I transferred the code to main signup function. I tried to see alert in signUpStarting() function but there I am getting response of just fourth page values and other values are showing nothing as the variables are null.
I am not getting how to save variable values for always without using localStorage or cookies and POSTing all data to server.And I think this would have been easier if I would know to code for all html pages for my site to single JS file.
Please help me !
I am not getting how to save variable values for always without using localStorage or cookies and POSTing all data to server.And I think this would have been easier if I would know to code for all html pages for my site to single JS file.
This is exactly right. You cannot store data in memory between page loads in a web browser environment because all javascript variables are naturally destroyed when the browser navigates away from the page to a new page (even if they use the same javascript on both pages). Thus, you have to save it somewhere with more permanence: localStorage, cookies, or on the server via POST or GET.
What I would recommend is scrapping the four different html pages and simply using one html page that changes dynamically as the user fills in data. This way the browser will not eliminate data before you are ready to POST it to the server.
I've been trying Google Apps Script a submit button using data validation ranges, however I'm struggling.
function submit2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var IBR = ss.getSheetByName('IBR');
var lastColumn = IBR.getLastColumn()+1;
var cell = IBR.getRange(7,5,7);
var total = ss.getSheetByName('MS').getRange('G2:G13').getValue();
cell.setValue(total);
}
Here's picture of data and below the validation, the submit image once click should reflect that date and take numbers and put them on a second page
And there's where second page would receive the information
I am making a chat function, in which I have put the chat records with while loop but I want to get new records with out refresh the div at the real time.
But If no record is updated new so div doesn't refresh because of scroll force me to bottom.
Use this (I guess u have php installed, you use a PHP page):
var ajaxurl = "updatepage.php(CORRECT URL HERE)";
var data = {};
data["CurBox"] = document.getElementById(IDOFCHATBOX).innerHTML
$.post(ajaxurl, data
, function (response) {
func(response);
});
and make sure you run checks on that the current chatbox is not already the same as when it would be updated! :)
use the post method inside the refreshscript to get the current chatbox contents
I have some JSP code I'm trying to modify.
I have a user object that holds and generates a CSRF values. Currently, this value is set at the start of the application and remains constant throughout the application. I have to change this such that it resets each time a new page is accessed.
The code currently is
<script type='text/javascript'>
var csrfTokenName = 'csrfValue';
var csrfTokenValue = '${user.csrfValue}'; //user is the object, which also contains a setCsrfValue() method that generates the CSRF value
var csrfParam = {csrfValue : csrfTokenValue};
function csrfUrl(url) {
if (url.indexOf('?') == -1) {
//setCSRF code here
return url+'?'+csrfTokenName+'='+csrfTokenValue;
} else {
//setCSRF code here
return url+'&'+csrfTokenName+'='+csrfTokenValue;
}
}
</script>
I tried adding this
<%
User user = (User) session.getAttribute('user'); //fixed typo
%>
In the script but the page won't load (on that note, is there a tool/setting for debugging JSP, using STS with Tomcat and Firefox)
How do I reference this object correctly so that I can call setCsrfValue();
I tried the following but the page didn't load
<%
User user = (User) session.getAttribute('user'); //fixed typo
user.setCsrfValue();
%>