file_get_contents while bypassing javascript detection - javascript

I am trying to save a page as a PDF file, and to do so I am trying to read the content of that page then using a PDF library to create the file.
The issue I am facing is that when reading the content using below code I am receiving "Please enable JavaScript to view the page content." instead of the page content
<?php
$url='https://www.carfax.com/VehicleHistory/p/Report.cfx?vin=1J4RR5GG5BC586221&csearch=0&partner=GAZ_0';
//file_get_contents() reads remote webpage content
$lines_string=file_get_contents($url);
//output, you can also save it locally on the server
echo htmlspecialchars($lines_string);
?>
How can I bypass this java-script error or should i use a different approach ?
This is the response I am getting:
<html>
<head>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="-1"/>
<meta http-equiv="CacheControl" content="no-cache"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="data:;base64,iVBORw0KGgo="/>
<script> (function(){ var securemsg; var dosl7_common; window["bobcmn"] = "11111010101010200000002200000005200000000289128f7a200000096300000000300000000300000006/TSPD/300000008TSPD_101300000005https200000000200000000"; window.jar=!!window.jar;try{(function(){try{var jj,Jj,Lj=1,Zj=1,Sj=1;for(var ij=0;ij<Jj;++ij)Lj+=2,Zj+=2,Sj+=3;jj=Lj+Zj+Sj;window._O===jj&&(window._O=++jj)}catch(Ij){window._O=jj}var oJ=!0;function OJ(J){J&&(oJ=!1,document.cookie="brav=ad");return oJ}function _J(){}OJ(window[_J.name]===_J);OJ("function"!==typeof ie9rgb4);OJ(/\x3c/.test(function(){return"\x3c"})&!/x3d/.test(function(){return"'x3'+'d';"})); var iJ=window.attachEvent||/mobi/i.test(window["\x6e\x61vi\x67a\x74\x6f\x72"]["\x75\x73e\x72A\x67\x65\x6et"]),IJ=+new Date+6E5,ol,_l,Il=setTimeout,jL=iJ?3E4:6E3;function JL(){if(!document.querySelector)return!0;var J=+new Date,O=J>IJ;if(O)return OJ(!1);O=_l&&ol+jL<J;O=OJ(O);ol=J;_l||(_l=!0,Il(function(){_l=!1},1));return O}JL();var LL=[17795081,27611931586,1558153217]; function oL(J){J="string"===typeof J?J:J.toString(36);var O=window[J];if(!O.toString)return;var s=""+O;window[J]=function(J,s){_l=!1;return O(J,s)};window[J].toString=function(){return s}}for(var ZL=0;ZL<LL.length;++ZL)oL(LL[ZL]);OJ(!1!==window.jar);(function(){var J={decrypt:function(J){try{return JSON.parse(function(J){J=J.split("l");var O="";for(var s=0;s<J.length;++s)O+=String.fromCharCode(J[s]);return O}(J))}catch(s){}}};return J={configuration:J.decrypt("123l34l97l99l116l105l118l101l34l58l34l110l111l34l44l34l100l101l98l117l103l103l105l110l103l34l58l34l110l111l34l44l34l109l111l100l117l108l101l49l34l58l34l101l110l97l98l108l101l100l34l44l34l109l111l100l117l108l101l50l34l58l34l101l110l97l98l108l101l100l34l44l34l109l111l100l117l108l101l51l34l58l34l101l110l97l98l108l101l100l34l44l34l109l111l100l117l108l101l52l34l58l34l101l110l97l98l108l101l100l34l125")}})(); var sL=3;window.Ls={Os:"087ba4d0fa0178004caafc50a30d48046efd9a15f604d0926f4f95da1a85d369a6d1815489a54acc4a49a5998f87f099792ce5cf3c00ed82cb613e80bec837da827a4967e05d64d8670f7d97250745b00db5a2d96701cfc9d19e00ad5ebfd2aff76046976642518c76938888a8f784eed5b5ea881a1e3668f9b030002df03262"};function l(J){return 645>J}function L(J){var O=arguments.length,s=[];for(var S=1;S<O;++S)s.push(arguments[S]-J);return String.fromCharCode.apply(String,s)}function z(J,O){J+=O;return J.toString(36)}(function SL(O){O&&"number"!==typeof O||("number"!==typeof O&&(O=1E3),O=Math.max(O,1),setInterval(function(){SL(O-10)},O))})(JL());})();}catch(x){document.cookie='brav=oex'+x;}finally{ie9rgb4=void(0);};function ie9rgb4(a,b){return a>>b>>0}; })(); </script>
<script type="text/javascript" src="/TSPD/086821c3deab2000f497f4a10d45047d2c741eba0afdeced26cf36a836d13b181cb57773ccf959f0?type=7"></script>
<noscript>Please enable JavaScript to view the page content.</noscript>
</head>
<body> </body>
</html>

The problem is that the site is doing javascript detection on the page you're trying to load meaning that's more than likely serving up a mostly blank document with noscript tags and script tag to load the rest of the content. You cannot bypass this with cURL the way you are trying. Instead you'll need a headless browser with a javascript engine. Selenium Web Driver is one such solution. I found this gist for you as well: https://gist.github.com/evandrix/3694955

Related

Saving an offline single html page application - dynamically filled with crud javascript - on client side only

I'm very new here and hope I can express myself clearly.
I'm a teacher and I'd like to create a single html file with interactivity (kind of empty form) that can be loaded without any server : student should for example be provided a file like myform.html.
This means html, css and javascript should all be in the document.
Once the students have opened and filled their names and answers, i'd like them to be able to save locally the modified document as another .html - Let's say johndoeform.html - file.
If I load a simple html file from my local storage and I fill - for example textareas - and try to save the modified page with "save as" in my web browser (safari) I get the unmodified page when I open it again.
I'm aware that an app that stores a lot of datas should rely on a server and data base app. But for a simplistic form/quiz that really should be loaded without any additional software nor an internet connection I feel that this way should be more straight forward.
I'm a noob with java script and I've seen quite some things around about generating blobs with html content but I'm not sure how to get the whole modified document, generate a blob with it then save the whole thing via a new html document.
Perhaps a JS generated download link could do the trick ?
For the purpose here's a simple example of code I could use :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h3>Search on wikipedia</h3>
What's the difinition of ENERGY:<br>
<textarea id="energyDef" placeholder="Write your definition here and save your work" cols=40 rows=6>
</textarea>
<p>Click the button to save as an html file.</p>
<button type="button" onclick="saveHtml()">Save</button>
<script>
function saveHtml() {
// how can I generate and export the whole modified page from here
}
</script>
</body>
</html>
Let me start by giving the answer and saying you probably shouldn't do this and instead below for reason and better solutions
You can take the value of the textarea and directly modify the innerText of it to hard code the answer into the html and then simply export it by using a blob
You can add classes to the answer field and loop through it so that you wouldn't have to manually enter the code for each field.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h3>Search on wikipedia</h3>
What's the difinition of ENERGY:<br>
<textarea id="energyDef" placeholder="Write your definition here and save your work" cols=40 rows=6></textarea>
<p>Click the button to save as an html file.</p>
<button type="button" onclick="saveHtml()">Save</button>
<script>
function saveHtml() {
answer_field = document.getElementById("energyDef");
answer_field.innerText = answer_field.value;
var a = document.createElement("a");
var file = new Blob([document.documentElement.outerHTML], {type: "text/plain"});
a.href = URL.createObjectURL(file);
a.download = "dump.html";
a.click()
}
</script>
</body>
</html>
A better way would be to export the data as a machine readable file like JSON , and implement a simple drag and drop to load the data back if you need it as shown in the html file.
Having it as a machine readable format would allow a much easier time to import into a database in the future or simply allow you to easily be able to write a script to get percentage of correct answer for a given question by the class for simple fixed answer
It would also allow you to quickly glance just the answers with a simple notepad program if proper formatting was used in the export process, ie the "space" parameters in JSON.stringify()

Can I load JavaScript Functions on One page then redirect to another?

I have an old application that I can not modify in anyway including editing the HTML in anyway directly. I had to create a redirect html page for people to load in order to always get everyone to the correct location.
Can I load a JavaScript on Page one, and keep it loaded?
I.E.
<html>
<head>
<script type="text/javascript">
function getMyAppProductID()
{
//Do the Java action to find the Product ID.
}
</ script>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<META http-equiv="refresh" content="0;URL=http://MyAppURL.internalUrl.local/StartupScript.jsp">
<title>Load...</title>
</head>
<body>
<p>Loading My App</p>
</body>
</html>
Then when I am looking at my application I want to be able to call the function I wrote.
IE. I have a floating button that does the getMyAppProductID Function.

how to sent hindi or other language to another page with rich text editor

When I am Input This "आप सभी दोस्तों को नमस्कार" and send with post method. this text show like this "आप सभी दोसà¥à¤¤à¥‹à¤‚ को नमसà¥à¤•à¤¾à¤°" but i want to show sent data as it is.
Input Data Img
Send Data Img
i am persian and i know this problem finely :
use this line in :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
in submission page and show page
You should always specify the encoding used for an HTML page. If you don't,so will cause browsers to guess the encoding, which can lead to cross-site scripting attacks if they guess incorrectly.
Always declare the encoding of your document using a meta element with a charset attribute, or using the http-equiv and content attributes (called a pragma directive). The declaration should fit completely within the first 1024 bytes at the start of the file, so it's best to put it immediately after the opening head tag.
for exam
<!DOCTYPE html>
<html lang="hi">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
.....
</head>
<body>
........
</body>
</html>

Adding an external JavaScript file in NetBeans and linking with the index file

I have added a JavaScript file into my existing project and referred that in the HTML file. The file structure is shown as its in the attachment. After I run the program, the output does not display what it is supposed to be.
Is there anything wrong with my file tree (how I am adding file into the project) or I am not referring the script the in the correct way?
Here is how my program looks like:
index:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="newjavascript.js" type="text/javascript"></script>
</head>
<body>
<p id="demo"></p>
</body>
</html>
.JS:
document.getElementById("demo").innerHTML = 7+9;
It seems to be everything is ok with your project structure and refererring to js file inside index.html. However, the demo paragraph does not display what you want because it can be just not loaded in the time when your newjavascript.js is executed. I think you can try to modify it in the following way:
window.onload = function () {
document.getElementById("demo").innerHTML = 7+9;
};
Using onload function of window object you wait until a page (including demo paragraph) is loaded - and after it change its content.

Is it possible to load electron webContents from an in memory html string?

Let's say I've got 2 processes:
Process 1 is sending to process 2 a valid html string:
ipcRenderer.send('open-window-from-string',
'<!DOCTYPE html>' + '<html>' + htmlElement.innerHTML + '</html>');
Process 2 (Electron Main-Process) is trying to open a new window from that string:
ipc.on('open-window-from-string', (event, htmlString) => {
const windowFromString= BrowserWindow.fromWebContents(htmlString);
}
I know I could save the html as an actual html file. That way everything worked while using:
loadURL(`file://${__dirname}/windowFromString.html`);
However that would cause unnecessary read/write actions.
That's why I am trying to load a new window from a htmlString out of my memory.
So again the question is:
Is it possible to load electron webContents from an in memory html string?
Thanks in advance for any help.
Regards,
Megajin
in Chrome, you can display inline html pages by navigating URL with data: protocol such as data:text/html;charset=utf-8,<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>MyYTitle</title> <style type="text/css"> </style></head> <body>Hello world from Lyon, FR</body>
It works the same in Electron.
Can you try opening a window with loadURL('data:text/html;charset=utf-8,<YOUR HTML/>');?
Well, perhaps you cannot directly load whole html. As a workaround, you can open a new browser window with just contents as:
<html>
<head></head>
<body></body>
</html>
After you open this you can use browserWindow.webContents.evaluate() to load actual HTML passed as String. If required you can use webContents.reload() for changes to take effect.

Categories

Resources