JS uses document to obtain page node information and perform string interception

1. Determine the node name

     1.getElementById

      2.getElementsByTagName

      3.getElementsByClassName

      4.querySelector

2. Obtain information under the node name

 

var 字段名 = document.getElementsByClassName("节点名" );
例如:
var arr = document.getElementsByClassName("a");
console.log(arr);//打印输出

The results displayed on the f12 console

 3. Intercept the obtained information

var Shop_info = arr[1].outerText;//获取数组里第二项的outerText的值
console.log(Shop_info)//输出的内容为xxx\nID:123456
var arr1 = Shop_info.split("\nID:");//截取\nID:前后的值
var Shop_Name = arr1[0];//第一个值为: xxx
var Shop_Id = arr1[1];//第二个值为:   123456
console.log(Shop_Id)
console.log(Shop_Name)

 

 

Guess you like

Origin blog.csdn.net/qq_46057971/article/details/130603563