V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
songdg
V2EX  ›  程序员

关于 Javascript/DOM 中 querySelector()提取 HTML 中的信息

  •  
  •   songdg · Nov 2, 2020 · 2002 views
    This topic created in 2008 days ago, the information mentioned may be changed or developed.
    想知道除了 innerHTML 和 InnerText 之外还有没有其他方法。像用 querySelectorAll("td")获取这段 html 信息之后,有没有方法直接得到('/aic/SearchCorporationTask?service=colligateSearchInterface&sFromSupervision=fromSupSearch&isUseDataCentre=true&entityNo=c1788671-0169-1000-e000-b7240a0c0115')和('xyz 公司')这两段信息。
    <td>&nbsp;1
    </td>
    <td>&nbsp;<a
    href="javascript:call('/aic/SearchCorporationTask?service=colligateSearchInterface&sFromSupervision=fromSupSearch&isUseDataCentre=true&entityNo=c1788671-0169-1000-e000-b7240a0c0115','xyz 公司')">91441900999999999z
    </a></td>
    <td>&nbsp;樟村教育路 x 号 y 室
    </td>
    4 replies    2020-11-02 15:52:35 +08:00
    cyrbuzz
        1
    cyrbuzz  
       Nov 2, 2020
    为啥不进一步 querySelect('a')呢...
    daimon1
        2
    daimon1  
       Nov 2, 2020
    用 a.href 获取,然后正则提取目标字符串的内容
    daimon1
        3
    daimon1  
       Nov 2, 2020
    xxxx.match(/\'(.*?)\'/ig).map(str => str.substr(1, str.length - 2))
    mostkia
        4
    mostkia  
       Nov 2, 2020
    var str = document.querySelector('td a').src;
    var strArr = str.split(',');
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   875 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 22:56 · PVG 06:56 · LAX 15:56 · JFK 18:56
    ♥ Do have faith in what you're doing.