JS原生取浏览器数据代码

‌取出所有的a标签链接

document.querySelectorAll('a')[0].href

‌取出所有的a标签 属性为data-testid="product-card-link"

document.querySelectorAll('a[data-testid="product-card-link"]')[0].href

取出所有的a标签class为a-link-normal s-faceout-link aok-block s-no-outline puis-expand-height a-text-norma

document.querySelectorAll('a.a-link-normal.s-faceout-link.aok-block.s-no-outline.puis-expand-height.a-text-normal')[0].href

document.querySelectorAll('[name="submit.addToCart"]')[2].dataset.url
可输出data-url的值

‌取出网页HTML源码

document.getElementsByTagName('html')[0].innerHTML

‌点击按钮或者网页

document.querySelector('字段名').click()

获取元素从顶边到元素的高度

document.querySelector('#navbar > div.nav-searchbar-wrapper').offsetTop

替换指定参数的标题,执行脚本命令

document.querySelector('#resultItems > li:nth-child(5) > a').href="链接"

通过网页Class取出动态的ID,元素名称

document.getElementsByClassName('a-size-base atwl-list-name-expand a-nowrap')[0].id

js 动态加载 JQ库

var script=document.createElement("script"); 
script.type="text/javascript"; 
script.src="https://code.jquery.com/jquery-1.12.4.min.js"; 
document.getElementsByTagName('head')[0].appendChild(script); 

通过js代码,读取谷歌浏览器localStorage的数据

/**
 * 把 localStorage 中的所有键值对读取出来,返回一个数组
 * @returns {Array<{key: string, value: string}>}
 */
function getAllLocalStorage() {
  const result = [];

  for (let i = 0; i < localStorage.length; i++) {
    const key   = localStorage.key(i);          // 取第 i 个 key
    const value = localStorage.getItem(key);    // 取对应的 value
    result.push({ key, value });                // 存进数组
  }

  return result;   // 这里就是你想要的返回值
}

// 用法示例
const allItems = getAllLocalStorage();
console.log(allItems);          // [{key:'foo', value:'bar'}, ...]


如果您喜欢本站,点击这儿不花一分钱捐赠本站

这些信息可能会帮助到你:下载帮助 | 报毒说明 | 进站必看

修改版本安卓软件,加群提示为修改者自留,非本站信息,注意鉴别

(0)

发表回复

评论问题之前, 点击我,能帮你解决大部分问题

评论列表(0条)

请用支付宝扫一扫完成支付