自动单击表中的JavaScript链接

自动单击表中的JavaScript链接,javascript,hyperlink,click,greasemonkey,tampermonkey,Javascript,Hyperlink,Click,Greasemonkey,Tampermonkey,我得到了如下HTML表: <tbody> <tr> <td><a href="link1"></td> <td><a href=link2"></td> <tr> <td><a href="link3"></td> <td><a href=link4">

我得到了如下HTML表:

<tbody>
    <tr>
        <td><a href="link1"></td>
        <td><a href=link2"></td>
    <tr>
        <td><a href="link3"></td>
        <td><a href=link4"></td>
   </tr>
</tbody>
它的行比这个多很多,但这只是我问题的一部分。我知道Javascript使用。单击以单击链接,但我想知道是否有任何方法可以选择第一行第一列中的链接,因为在不同的网页上,第一列中的第一个链接将不同于此网页上的第一个链接。如果可能的话,我怎么做?非常感谢你。我自己调查了一下,试图找到答案,但没有找到答案。如果有帮助,我将使用Tampermonkey运行脚本。谢谢你的帮助


Lucy

这将返回表中的第一个链接

document.querySelector('table a')
如果您想从网页中获得第一个链接,请使用

document.querySelector('a')
如果你想点击它,那么

document.querySelector('table a').click()
或者如果你想在不同的窗口打开

window.open(document.querySelector('table a').href)

document.querySelector('#profile_creatures table a').click()

这将返回表中的第一个链接

document.querySelector('table a')
如果您想从网页中获得第一个链接,请使用

document.querySelector('a')
如果你想点击它,那么

document.querySelector('table a').click()
或者如果你想在不同的窗口打开

window.open(document.querySelector('table a').href)

document.querySelector('#profile_creatures table a').click()

您可以使用JQuery来实现这一点

var attribute = $('td a:first').attr('href');
console.log(attribute);

您可以使用JQuery来实现这一点

var attribute = $('td a:first').attr('href');
console.log(attribute);

这似乎对我不起作用。我使用的是:window.openDocument.querySelector'table a',\u self;这样行吗?还是我遗漏了什么。是否需要使用。单击?@TurtleBo document.querySelector“表a”。单击将do@TurtleBo:有没有办法找到哪些表可能有链接?或者你正在寻找哪种链接?或者,我可以创建一个选择器accordingly@TurtleBo:try,window.opendocument.querySelector'profile_biotes table a'.hrefdocument.querySelector'profile_biotes table a'.click这似乎对我不起作用。我使用的是:window.openDocument.querySelector'table a',\u self;这样行吗?还是我遗漏了什么。是否需要使用。单击?@TurtleBo document.querySelector“表a”。单击将do@TurtleBo:有没有办法找到哪些表可能有链接?或者你正在寻找哪种链接?或者,我可以创建一个选择器accordingly@TurtleBo:try,window.opendocument.querySelector'profile_biotes table a'。hrefdocument.querySelector'profile_biotes table a'。单击我知道问题出在哪里。页面上有多个表,但它们没有ID或任何东西。我有办法解决这个问题吗?哦,等等。第一个有,我想要的桌子有我知道问题是什么。页面上有多个表,但它们没有ID或任何东西。我有办法解决这个问题吗?哦,等等。第一张有,我要的桌子也有