通过用户脚本点击页面上的属性

问题描述

我正在尝试在 chrome tampermonkey 中创建一个用户脚本,该脚本将自动单击 this页面中的“Gen.lib.rus.ec”链接。 classname 始终是动态的,但不是标题名称。我知道如何通过类名而不是标题来让它工作。请提出一些建议。

// ==UserScript==
// @name         libgen  clicker
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @include      *://libgen.rs/*
// @match      *://libgen.rs/*
// @include      *://library.lol/*
// @icon         https://www.google.com/s2/favicons?domain=libgen.rs
// @grant        none
// ==/UserScript==
    
setTimeout(function() {
document.getattribute("Gen.lib.rus.ec")[0].click();
},500);  

解决方法

您可以使用 a[title="Gen.lib.rus.ec"] CSS 选择器,例如document.querySelector 根据标题属性获取正确的元素。