我正在尝试从网站上抓取数据。我的问题是,必须提取整个页面才能提取数据。
还有其他方法可以代替创建空元素并在该元素上使用getElementByClassName
吗?
$.getJSON('URL' + encodeURIComponent('websiteURL' + retrievedData.postnr) + '&callback=?', function(data) {
$(".newHtml").append(data.contents);
var elements = document.getElementsByClassName("The class name that I am looking for");
for (var i = 1; i < elements.length; i++) {
var header = elements[i].getElementsByTagName("h2")[0].textContent;
$(".add").append(header);
for (var x = 0; x < 3; x++) {
var pris = elements[i].getElementsByClassName("Class name inside with certain content inside the other class")[x].textContent;
var info = elements[i].getElementsByClassName("Class name inside with certain content inside the other class")[x].textContent;
$(".add").append("<div class='priser'><h3 class='pris'>" + pris + "</h3>" + "<p class='info'>" + info + "</p></div>");
}
}
$(".newHtml").remove();