I thought this would work but obviously I am doing something wrong. I need to get data from a lot of html files and figured I would write a quick scraper program. All the files are local. Code is below. The html from the url loads into the div ‘scrapedHTML’ ok. But when I then try to console.log the html of that div I get nothing and I’m not sure why. Any help would be appreciated.
<body class="home">
<header class="hd1">
</header>
<contentWrapper>
<div id="scrapedHTML" style="position:absolute; top: 150px; left: 150px; width: 800px; height: 200px; border: 1px solid black; overflow-y:scroll;"></div>
<div id="displayData" style="position:absolute; top: 400px; left: 150px; width: 800px; height: 500px; border: 1px solid black; ">
</div>
</contentWrapper>
<footer class="f1">
</footer>
<!-- jQuery version might not be the latest; check jquery.com -->
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script langauge="javascript">
$(document).ready(function() {
var scrapeThisURL = "oc-bloodloss.html";
$('#scrapedHTML').load(scrapeThisURL);
var capturedHTML = $("#scrapedHTML").html();
console.log(capturedHTML);
});
</script>
</body>
</html>
.loadmethod is asynchronous.You should do this instead:
Note that the code is to specifically obtain the html from the div. You could do this which would be better: