如何根据 URL 中的开始文本 select 页面上的所有 href 值?

How to select all href values on a page based on beginning text in URL?

我有一个包含数百个下载链接的网页。每个下载链接的 HTML 如下所示:

<a href = 'viewlinks.php?regid=190404... '

只有在最后一个 0404 之后,每个 URL 才有唯一的编号。我想 select 页面上以 viewlinks.php?regid=190404 开头的所有 href 值。有办法实现吗?

无法选择页面上的所有锚元素,因为有些 href 值我不想 select。我想要的下载链接也没有唯一 ID 或 类。

你可以在 JS 中做这样的事情。使用 querySelectorAll.

const links = document.querySelectorAll("a[href^='viewlinks.php?regid=190404']");

console.log(links);
<a href='viewlinks.php?regid=1904041234'>1234</a>
<a href='viewlinks.php?regid=1904041222'>1222</a>