導航:首頁 > 編程語言 > js動態內容

js動態內容

發布時間:2023-07-09 19:13:22

A. 怎麼爬取網頁的動態內容,很多都是js動態生

抓取動態頁面有兩種常用的方法,一是通過javaScript逆向工程獲取動態數據介面(真實的訪問路徑),另一種是利用selenium庫模擬真實瀏覽器,獲取JavaScript渲染後的內容。但selenium庫用起來比較繁瑣,抓取速度相對較慢,所以第一種方法日常使用較多。

B. 只用js如何實現表格內容的動態修改

<body>

<tableid='test'>//定義一個table

<tr>

<td></td><td></td>

</tr>

</table>

<script>

vartb=document.getElementById('test');//獲取表格的dom節點

vartd=tb.rows[0].cells[0];//獲取0行0列的td單元格

td.innerHTML='222';//動態修改表格的內容為222

</script>

</body>

思路:

1、獲取表格的dom節點

2、通過rows和cells定位td單元格

3、通過修改innerHTML

(2)js動態內容擴展閱讀:

JS實現動態表格的新增,修改,刪除操作

一、相關JS函數

function setParamslist() {

var tab = document.getElementById("tab");

//表格行數

var rows = tab.rows.length ;

//表格列數

var cells = tab.rows.item(0).cells.length ;

//alert("行數"+rows+"列數"+cells);

var rowData = "";

for(var i=1;i<rows;i++) {

var cellsData = new Array();

for(var j=0;j<cells-1;j++) {

cellsData.push(tab.rows[i].cells[j].innerText); 

}

rowData = rowData + "|" + cellsData;

}

document.getElementById("paramslist").value = rowData;

}

//打開相關新增應用參數界面

function openAppParamsPage() {

var param = new Object();

//這個參數一定要傳。

param.win = window;

param.id = 100;

param.name = "test";

param.birthday = new Date();

var result = window.showModalDialog("addParamsItem","dialogWidth:500px;dialogHeight:600px;dialogLeft:200px;dialogTop=200px");

//var temp = document.getElementById("paramslist").value;

//document.getElementById("paramslist").value = temp + result;

addSort(result);

}

// 增加應用參數函數

function addSort(data) {

var name = data;

if(name == ""||name==undefined ) {

return;

}

console.log(data);

var params = data.split(",");

var paramName = params[0];

var paramCode = params[1];

var paramValue = params[2];

var row = document.createElement("tr");

row.setAttribute("id", paramCode);

var cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramName));

row.appendChild(cell);

cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramCode));

row.appendChild(cell);

cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramValue));

row.appendChild(cell);

var deleteButton = document.createElement("input");

deleteButton.setAttribute("type", "button");

deleteButton.setAttribute("value", "刪除");

deleteButton.onclick = function () { deleteSort(paramCode); };

cell = document.createElement("td");

cell.appendChild(deleteButton);

row.appendChild(cell);

document.getElementById("sortList").appendChild(row);

}

// 刪除應用參數函數

function deleteSort(id) {

if (id!=null){

var rowToDelete = document.getElementById(id);

var sortList = document.getElementById("sortList");

sortList.removeChild(rowToDelete);

}

}

二、彈出框頁面,新增或者修改參數,並回寫相關數據。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>新增應用</title>

<#include "/views/head.html"/>

</head>

<body>

<div class="body-box">

<div class="clear"></div>

<form >

<table width="100%" cellspacing="1" cellpadding="2" border="0"class="pn-ftable">

<tr>

<td>參數名稱:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramName" name="paramName"/></td>

</tr>

<tr>

<td>參數編碼:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramCode" name="paramCode" required="true" /></td>

</tr>

<tr>

<td>參數值:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramValue" name="paramValue" required="true" /></td>

</tr>

<tr>

<td align="center" colspan="4">

<input type="submit" value="保存" onclick="returnResult();"/>

<input type="button" value="返回" onclick="closeWindow();"/>

</td>

</tr>

</table>

</form>

</div>

</body>

</html>

<script type="text/javascript">

//直接關閉窗口

function closeWindow() {

window.close();

}

//獲取值,組裝後返回

function returnResult() {

if(!$('form').valid())

return;

var paramName = document.getElementById("paramName");

var paramCode = document.getElementById("paramCode");

var paramValue = document.getElementById("paramValue");

//alert("value is " + paramName.value + "," + paramCode.value + "," + paramValue.value);

var result = paramName.value + "," + paramCode.value + "," + paramValue.value;

window.returnValue = result;

window.close();

}

</script>

C. 如何用python爬取js動態生成內容的頁面

抓取js動態生成的內容的頁面有兩種基本的解決方案

1用dryscrape庫動態抓取頁面
js腳本是通過瀏覽器來執行並返回信息的,所以,抓取js執行後的頁面,一個最直接的方式就是用python模擬瀏覽器的行為。WebKit 是一個開源的瀏覽器引擎,python提供了許多庫可以調用這個引擎,dryscrape便是其中之一,它調用webkit引擎來處理包含js等的網頁!

2 selenium web測試框架

selenium是一個web測試框架,它允許調用本地的瀏覽器引擎發送網頁請求,所以,它同樣可以實現抓取頁面的要求。

D. js動態添加內容

第一個:a,創建一個img元素,然後添加到div節點下面。
第二個:innerHTML , 直接用HTML代碼加入。

<!--
varimg=document_createElement_x('img'),
fff=document.getElementByIdx_x('aaa');
img.setAttribute('src','http://www.blueidea.com/articleimg/bbsimg/topic5.gif');
img.style.position='absolute';
img.style.left=fff.offsetLeft+20+'px';
img.style.top=fff.offsetTop+30+'px';
fff.a(img);
//-->


<script>
onload=functionf(){
document.getElementByIdx_x_x("insert").innerHTML='<imgsrc="new_banner.jpg"height="100"width="100"/>';
}
</script>
<divid="insert"></div>

E. js動態顯示文本內容

<?php
$filename="1.txt";
$filename2="2.txt";
$handle=fopen($filename,"r");
$handle2=fopen($filename2,"r");
//通過filesize獲得文件大小,將整個文件一下子讀到一個字元串中
$contents=fread($handle,filesize($filename));
$contents2=fread($handle2,filesize($filename2));
fclose($handle);
var_mp($contents);
var_mp($contents2);
echo'<br>';
echo"$contents-$contents2*2";
echo'<br>';
echo$contents-$contents2*2;
?>

你可以將這兩個數值傳遞到前端用js計算. 反正已經知道了結果.

至於實時動態顯示最新的結果. 如果頁面不刷新也可以獲取, 那麼就用ajax做或者websocket做.

F. 只用js如何實現表格內容的動態修改

<body>

<tableid='test'>//定義一個table

<tr>

<td></td><td></td>

</tr>

</table>

<script>

vartb=document.getElementById('test');//獲取表格的dom節點

vartd=tb.rows[0].cells[0];//獲取0行0列的td單元格

td.innerHTML='222';//動態修改表格的內容為222

</script>

</body>

思路:

1、獲取表格的dom節點

2、通過rows和cells定位td單元格

3、通過修改innerHTML

(6)js動態內容擴展閱讀:

JS實現動態表格的新增,修改,刪除操作

一、相關JS函數

function setParamslist() {

var tab = document.getElementById("tab");

//表格行數

var rows = tab.rows.length ;

//表格列數

var cells = tab.rows.item(0).cells.length ;

//alert("行數"+rows+"列數"+cells);

var rowData = "";

for(var i=1;i<rows;i++) {

var cellsData = new Array();

for(var j=0;j<cells-1;j++) {

cellsData.push(tab.rows[i].cells[j].innerText);

}

rowData = rowData + "|" + cellsData;

}

document.getElementById("paramslist").value = rowData;

}

//打開相關新增應用參數界面

function openAppParamsPage() {

var param = new Object();

//這個參數一定要傳。

param.win = window;

param.id = 100;

param.name = "test";

param.birthday = new Date();

var result = window.showModalDialog("addParamsItem","dialogWidth:500px;dialogHeight:600px;dialogLeft:200px;dialogTop=200px");

//var temp = document.getElementById("paramslist").value;

//document.getElementById("paramslist").value = temp + result;

addSort(result);

}

// 增加應用參數函數

function addSort(data) {

var name = data;

if(name == ""||name==undefined ) {

return;

}

console.log(data);

var params = data.split(",");

var paramName = params[0];

var paramCode = params[1];

var paramValue = params[2];

var row = document.createElement("tr");

row.setAttribute("id", paramCode);

var cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramName));

row.appendChild(cell);

cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramCode));

row.appendChild(cell);

cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramValue));

row.appendChild(cell);

var deleteButton = document.createElement("input");

deleteButton.setAttribute("type", "button");

deleteButton.setAttribute("value", "刪除");

deleteButton.onclick = function () { deleteSort(paramCode); };

cell = document.createElement("td");

cell.appendChild(deleteButton);

row.appendChild(cell);

document.getElementById("sortList").appendChild(row);

}

// 刪除應用參數函數

function deleteSort(id) {

if (id!=null){

var rowToDelete = document.getElementById(id);

var sortList = document.getElementById("sortList");

sortList.removeChild(rowToDelete);

}

}

二、彈出框頁面,新增或者修改參數,並回寫相關數據。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>新增應用</title>

<#include "/views/head.html"/>

</head>

<body>

<div class="body-box">

<div class="clear"></div>

<form >

<table width="100%" cellspacing="1" cellpadding="2" border="0" class="pn-ftable">

<tr>

<td>參數名稱:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramName" name="paramName"/></td>

</tr>

<tr>

<td>參數編碼:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramCode" name="paramCode" required="true" /></td>

</tr>

<tr>

<td>參數值:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramValue" name="paramValue" required="true" /></td>

</tr>

<tr>

<td align="center" colspan="4">

<input type="submit" value="保存" onclick="returnResult();"/>

<input type="button" value="返回" onclick="closeWindow();"/>

</td>

</tr>

</table>

</form>

</div>

</body>

</html>

<script type="text/javascript">

//直接關閉窗口

function closeWindow() {

window.close();

}

//獲取值,組裝後返回

function returnResult() {

if(!$('form').valid())

return;

var paramName = document.getElementById("paramName");

var paramCode = document.getElementById("paramCode");

var paramValue = document.getElementById("paramValue");

//alert("value is " + paramName.value + "," + paramCode.value + "," + paramValue.value);

var result = paramName.value + "," + paramCode.value + "," + paramValue.value;

window.returnValue = result;

window.close();

}

</script>

G. js動態獲取文本框的值

可以使用原生js的document.getElementById("id")方法
document.getElementById("id").value
也可以使用jQuery來獲取
$("#id").val()

H. js動態添加html內容

<!DOCTYPEHTML>
<html>
<head>
<title>yugi</title>
<metacharset=UTF-8/>
<styletype="text/css">
</style>
<scripttype="text/javascript">
varadd=function(dom)
{
varp=dom.parentElement,body=document.body,len=body.children.length;
varhtml=p.innerHTML.replace(p.children[p.children.length-1].outerHTML,"")
.replace(/(name["'=]+radio)[^"'s>]+/gim,'$1'+(len+1));
body.innerHTML+="<div>"+html+"</div>";
}
</script>
</head>
<body>
<body>
<div>
<label><inputtype="radio"name="radio1"value="學生"checked="checked"/>A.學生</label>
<label><inputtype="radio"name="radio1"value="教師"/>B.教師</label>
<label><inputtype="radio"name="radio1"value="管理員"/>C.管理員</label>
<label><inputtype="radio"name="radio1"value="管理員"/>D.管理員</label>
<inputtype="button"value="添加"name="add"onclick="add(this);">
</div>
</body>
</html>

I. 只用js如何實現表格內容的動態修改

<body>

<tableid='test'>//定義一個table

<tr>

<td></td><td></td>

</tr>

</table>

<script>

vartb=document.getElementById('test');//獲取表格的dom節點

vartd=tb.rows[0].cells[0];//獲取0行0列的td單元格

td.innerHTML='222';//動態修改表格的內容為222

</script>

</body>

思路:

1、獲取表格的dom節點

2、通過rows和cells定位td單元格

3、通過修改innerHTML

(9)js動態內容擴展閱讀:

JS實現動態表格的新增,修改,刪除操作

一、相關JS函數

function setParamslist() {

var tab = document.getElementById("tab");

//表格行數

var rows = tab.rows.length ;

//表格列數

var cells = tab.rows.item(0).cells.length ;

//alert("行數"+rows+"列數"+cells);

var rowData = "";

for(var i=1;i<rows;i++) {

var cellsData = new Array();

for(var j=0;j<cells-1;j++) {

cellsData.push(tab.rows[i].cells[j].innerText);

}

rowData = rowData + "|" + cellsData;

}

document.getElementById("paramslist").value = rowData;

}

//打開相關新增應用參數界面

function openAppParamsPage() {

var param = new Object();

//這個參數一定要傳。

param.win = window;

param.id = 100;

param.name = "test";

param.birthday = new Date();

var result = window.showModalDialog("addParamsItem","dialogWidth:500px;dialogHeight:600px;dialogLeft:200px;dialogTop=200px");

//var temp = document.getElementById("paramslist").value;

//document.getElementById("paramslist").value = temp + result;

addSort(result);

}

// 增加應用參數函數

function addSort(data) {

var name = data;

if(name == ""||name==undefined ) {

return;

}

console.log(data);

var params = data.split(",");

var paramName = params[0];

var paramCode = params[1];

var paramValue = params[2];

var row = document.createElement("tr");

row.setAttribute("id", paramCode);

var cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramName));

row.appendChild(cell);

cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramCode));

row.appendChild(cell);

cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramValue));

row.appendChild(cell);

var deleteButton = document.createElement("input");

deleteButton.setAttribute("type", "button");

deleteButton.setAttribute("value", "刪除");

deleteButton.onclick = function () { deleteSort(paramCode); };

cell = document.createElement("td");

cell.appendChild(deleteButton);

row.appendChild(cell);

document.getElementById("sortList").appendChild(row);

}

// 刪除應用參數函數

function deleteSort(id) {

if (id!=null){

var rowToDelete = document.getElementById(id);

var sortList = document.getElementById("sortList");

sortList.removeChild(rowToDelete);

}

}

二、彈出框頁面,新增或者修改參數,並回寫相關數據。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>新增應用</title>

<#include "/views/head.html"/>

</head>

<body>

<div class="body-box">

<div class="clear"></div>

<form >

<table width="100%" cellspacing="1" cellpadding="2" border="0" class="pn-ftable">

<tr>

<td>參數名稱:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramName" name="paramName"/></td>

</tr>

<tr>

<td>參數編碼:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramCode" name="paramCode" required="true" /></td>

</tr>

<tr>

<td>參數值:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramValue" name="paramValue" required="true" /></td>

</tr>

<tr>

<td align="center" colspan="4">

<input type="submit" value="保存" onclick="returnResult();"/>

<input type="button" value="返回" onclick="closeWindow();"/>

</td>

</tr>

</table>

</form>

</div>

</body>

</html>

<script type="text/javascript">

//直接關閉窗口

function closeWindow() {

window.close();

}

//獲取值,組裝後返回

function returnResult() {

if(!$('form').valid())

return;

var paramName = document.getElementById("paramName");

var paramCode = document.getElementById("paramCode");

var paramValue = document.getElementById("paramValue");

//alert("value is " + paramName.value + "," + paramCode.value + "," + paramValue.value);

var result = paramName.value + "," + paramCode.value + "," + paramValue.value;

window.returnValue = result;

window.close();

}

</script>

閱讀全文

與js動態內容相關的資料

熱點內容
網路評選一般有哪些 瀏覽:476
2021三支一扶報名數據在哪裡看 瀏覽:914
網路未備案怎麼打得開 瀏覽:987
計算機程序用什麼編程語言 瀏覽:324
linux入門常用命令 瀏覽:497
江寧區哪裡有數控編程培訓 瀏覽:778
java寫一個shape形狀類 瀏覽:744
win7如何設置word背景顏色 瀏覽:484
如何創造電腦編程語言 瀏覽:56
昂達平板電腦圖形密碼忘記怎麼辦 瀏覽:92
組織文件內容是什麼 瀏覽:183
0基礎如何學習智能編程 瀏覽:366
java程序員全攻略下載 瀏覽:715
網路逆向教程 瀏覽:135
iso文件如何重裝系統 瀏覽:750
ghost鏡像文件路徑如何恢復 瀏覽:832
搭建網站需要多少錢啊 瀏覽:599
編程貓怎麼設置背景亮度 瀏覽:177
qq文件破損 瀏覽:414
javapoi配置 瀏覽:608

友情鏈接