Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-06-17 08:13:41
Point:500 Replies:8 POST_ID:828559USER_ID:11059
Topic:
Apache Web Server;PHP Scripting Language;JavaScript
I would like to get the html DOM data from the follwing simple HTML page which
just output "after " to div tag at id="txt" after the body onload from javascript
function init() done
I use curl php with $dom.getElementById("txt")->nodeValue to extract
"after" but it just echo out"before" (at div tag) which is the value before excuting
javascript init() on body onload, Why ?
On FireFox firebug, we can see the complete javascript code is done and output
the "after" data when view the page source.
COuld we use php curl to extract the DOM data after parsing all javascript coding
and function execution is completed on the html web page.
I try $dom->validateOnParse = true; but it is still not working.
If we can see the "after" data on my IE broswer, we should be able to extract it
from curl php like browser's view source option , Right ?
Please advise
Duncan
<?php
include "include'/curl.php";
$url="http://www.mysite.com/simple.html";
$file_url=my_curl($url,"" , 7, TRUE,2,"");
}
if ($file_url) {
$dom = new DOMDocument();
$dom->validateOnParse = true;
$dom->loadHTML($file_url);
echo $dom->getElementById("txt")->nodeValue;
}
?>
/------------target simple.html page
just output "after " to div tag at id="txt" after the body onload from javascript
function init() done
I use curl php with $dom.getElementById("txt")->nodeValue to extract
"after" but it just echo out"before" (at div tag) which is the value before excuting
javascript init() on body onload, Why ?
On FireFox firebug, we can see the complete javascript code is done and output
the "after" data when view the page source.
COuld we use php curl to extract the DOM data after parsing all javascript coding
and function execution is completed on the html web page.
I try $dom->validateOnParse = true; but it is still not working.
If we can see the "after" data on my IE broswer, we should be able to extract it
from curl php like browser's view source option , Right ?
Please advise
Duncan
<?php
include "include'/curl.php";
$url="http://www.mysite.com/simple.html";
$file_url=my_curl($url,"" , 7, TRUE,2,"");
}
if ($file_url) {
$dom = new DOMDocument();
$dom->validateOnParse = true;
$dom->loadHTML($file_url);
echo $dom->getElementById("txt")->nodeValue;
}
?>
/------------target simple.html page
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head><script language="javascript" type="text/javascript" src="js/elib2.js"></script><script type="text/javascript">function init(){var i=1;b=7;document.getElementById("txt").innerHTML="after";}</script></head><body onload="init();"><div style="height:100px" id="txt">before</div></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:
Author: duncanb7 replied at 2024-06-17 12:08:12
Yes, after my study, you are right , php could not parse the javascript code.
The only way to solve the issue that might be
1-parse all remote site javascript , js file if any and echo all html code with javascript code ans save it in other new server html page with new iframe tag included. In the new html page, make some javascript code to save any information I want such as page's body width or height
2- ajax back the php file with query string which is consisted the information I want to send back such as the body width
Two steps run it on browers.
that might solve the issue on the cross-domain
The only way to solve the issue that might be
1-parse all remote site javascript , js file if any and echo all html code with javascript code ans save it in other new server html page with new iframe tag included. In the new html page, make some javascript code to save any information I want such as page's body width or height
2- ajax back the php file with query string which is consisted the information I want to send back such as the body width
Two steps run it on browers.
that might solve the issue on the cross-domain
Accepted Solution
Expert: hielo replied at 2024-06-17 10:22:25
500 points EXCELLENT
I use curl php with $dom.getElementById("txt")->nodeValue to extract
"after" but it just echo out"before" (at div tag) which is the value before excuting
javascript init() on body onload, Why?
"after" but it just echo out"before" (at div tag) which is the value before excuting
javascript init() on body onload, Why?
Because, unlike most browsers, curl does not execute javascript code - it doesn't have a built-in javascript parser. It simply retrieves the original source code. That's why you are seeing "before". Most browsers fetch the "original" html source code. Once they receive it, then IF the browser supports javascript AND the user has javascript enabled on his/her browser, then the browser will invoke its javascript interpreter so that it executes the javascript code.
The question is : could I extract the data in php by curl and DOM from
the remote site page with all javascript function is done like the simple
init() function on body noload ?
the remote site page with all javascript function is done like the simple
init() function on body noload ?
The correct answer is No.
I try $dom->validateOnParse = true; but it is still not working.
because the DOM parser does not interpret javascript either.
If we can see the "after" data on my IE broswer, we should be able to extract it
from curl php like browser's view source option , Right ?
from curl php like browser's view source option , Right ?
No. The "view source" feature is meant to reveal the original code (as saved on the server). The DOM that you see via Firebug is the "live" representation of the DOM at that moment in time. Since most browser's support javascript, you see "after" because the original DOM (in your example) has been altered via javascript from "before" to "after". But like I said, that does not happen if javascript is disabled/unsupported.
Author: duncanb7 replied at 2024-06-17 09:36:10
Be reminded the web page and php code is in different domain (cross-domain)
Author: duncanb7 replied at 2024-06-17 09:31:50
sorry it is no use the elib2.js, I forgot to delete it
THe question is : could I extract the data in php by curl and DOM from
the remote site page with all javascript function is done like the simple
init() function on body noload ?
THe question is : could I extract the data in php by curl and DOM from
the remote site page with all javascript function is done like the simple
init() function on body noload ?
Expert: Ray Paseur replied at 2024-06-17 09:25:24
What would I expect to find in "js/elib2.js" ?
Author: duncanb7 replied at 2024-06-17 08:43:10
sorry the code is no use
<script language="javascript" type="text/javascript" src="js/elib2.js"></script>
Just want to get the idea to solve the problem.
Is it we need to use proxy php script parsing all javascript file ?
<script language="javascript" type="text/javascript" src="js/elib2.js"></script>
Just want to get the idea to solve the problem.
Is it we need to use proxy php script parsing all javascript file ?
Author: duncanb7 replied at 2024-06-17 08:40:19
You can try my example and save it into your site. since my site
is blocked by my company to outside
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><script language="javascript" type="text/javascript" src="js/elib2.js"></script><script type="text/javascript">
function init()
{
var i=1;b=7;
document.getElementById("txt").innerHTML="after";
}
</script></head>
<body onload="init();">
<div style="height:100px" id="txt">before</div>
</body></html>
is blocked by my company to outside
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><script language="javascript" type="text/javascript" src="js/elib2.js"></script><script type="text/javascript">
function init()
{
var i=1;b=7;
document.getElementById("txt").innerHTML="after";
}
</script></head>
<body onload="init();">
<div style="height:100px" id="txt">before</div>
</body></html>
Expert: Ray Paseur replied at 2024-06-17 08:37:11
What is the URL of the site?