Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript document.getElementById(';idname';)。打印时,值仅返回[object HTMLInputElement]_Javascript_Web Scraping_Tampermonkey - Fatal编程技术网

Javascript document.getElementById(';idname';)。打印时,值仅返回[object HTMLInputElement]

Javascript document.getElementById(';idname';)。打印时,值仅返回[object HTMLInputElement],javascript,web-scraping,tampermonkey,Javascript,Web Scraping,Tampermonkey,因此,我使用了一个篡改猴子脚本,它将刮取一个单一页面的文本,返回页面上3个按钮的值(pick_0、pick_1和pick_2),并将它们打印到页面下方的框中。这比那更复杂,但老实说,我只是想让它先读懂愚蠢的价值观 所以,是的,让我痛苦的是,它没有正确地获取值,我不知道是它获取元素的方式,还是它获取页面的方式 而且,每次我在任何网站上找到答案时,他们都会指定添加“.value”来修复它,事实就是这样。所以我在一个死胡同,所以这个问题被张贴 一位朋友给了我一个页面抓取代码,我担心这可能不起作用。然而

因此,我使用了一个篡改猴子脚本,它将刮取一个单一页面的文本,返回页面上3个按钮的值(pick_0、pick_1和pick_2),并将它们打印到页面下方的框中。这比那更复杂,但老实说,我只是想让它先读懂愚蠢的价值观

所以,是的,让我痛苦的是,它没有正确地获取值,我不知道是它获取元素的方式,还是它获取页面的方式

而且,每次我在任何网站上找到答案时,他们都会指定添加“.value”来修复它,事实就是这样。所以我在一个死胡同,所以这个问题被张贴

一位朋友给了我一个页面抓取代码,我担心这可能不起作用。然而,我尝试了其他一些关于堆栈溢出的方法,但没有效果。 注意:TamperMonkey脚本被设置为只在我需要刮取的特定页面上运行,因此他没有在代码中真正指定它

function getLink(url) {
    return $.ajax(
        {
            type: 'GET',
            async: true,
            url:  url,
        });     
}   
我的变量:

function inputs() {
    var pick_0b = document.getElementById('pick_0').value;
    var pick_1b = document.getElementById('pick_1').value;
    var pick_2b = document.getElementById('pick_2').value;
}
它的打印部分工作正常,它可以打印具有类似语法的虚拟变量。但是是的,每次我试着打印出这些家伙中的一个,我要么得到这两个中的一个

undefined

[object HTMLInputElement] 
帮忙? 编辑:因此,按钮本身的HTML为:

<tr><td class="centered"><input type="submit" name="pick_0" value="longass string of randomized text here"  class="button" id="pick_0" /></td></tr>
<tr><td class="centered"><input type="submit" name="pick_1" value="longass string of secondary random text here"  class="button" id="pick_1" /></td></tr>
<tr><td class="centered"><input type="submit" name="pick_2" value="longass third string of random text here"  class="button" id="pick_2" /></td></tr>


要访问:


这两种方法都有效吗




编辑:你现在可能已经解决了这个问题,但如果没有

我又看了一眼你的pastebin文件。。。如果tampermonkey像greasemonkey一样挑剔,那么您的元数据块可能会有问题——请尝试将第二列全部对齐

你的:

// ==UserScript==
// @name       Result Reader
// @namespace  tarakore.com
// @version    1.0
// @description  Stupid description goes here.
// @match      http://www.(removedurl).com/game/* //Url removed because the site in question wouldn't want attention from this post.
// @copyright  2014+ Tarakore/Katiki
// @grant   GM_xmlhttpRequest
// @require       http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
// ==/UserScript==
可能是固定的:

// ==UserScript==
// @name         Result Reader
// @namespace    tarakore.com
// @version      1.0
// @description  Stupid description goes here.
// @match        http://www.(removedurl).com/game/* 
// @copyright    2014+ Tarakore/Katiki
// @grant        GM_xmlhttpRequest
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
// ==/UserScript==

此外,您还可以尝试删除版权行以进行检查。

尝试
.innerHtml
.innerText
而不是
.value
。如何将
getLink
连接到
输入?.innetHtml和.innerText不起作用,不过感谢您的回复。它们并不是真的,它们只是两个相互追逐的函数。然而,让我困惑的是,他给我这个函数的旧代码(在其中它是如何设置的,两个函数按顺序运行的),它工作得完美无缺。除了他的值,他抓取的是数字,而不是按钮上的文本字符串。你有没有在主帖子中添加“pick_0”等的html标记?谢谢你的回复,我尝试了你的回复,返回了相同的错误,所以我让它转到控制台,收到错误
参考错误:未定义拾取\u 0b
后跟大量。。。某物在我从其他评论者那里使用的所有其他方法上使用console时也发生了相同的错误。@Katiki我认为你没有使用greasemonkey,哈哈。。。函数外的代码在greasemonkey中运行良好。我想我需要看看你剩下的代码。。。看起来你在函数中设置这些变量,但它没有传递值…@Katiki在我的回答中添加了测试它不是greasemonkey,也就是说,呃。我不知道,我以前从未试过用它。它说它应该和firefox的greasemonkey扩展一样工作,但是chrome很挑剔。我将尝试这些测试,看看会发生什么。第一个测试没有返回任何东西(作为alert或console.log),第二个测试在chrome的控制台中返回与以前相同的错误。警报在tampermonkey中似乎不起作用。
function inputs() {
    var pick_0b = document.getElementsByName('pick_0');
    var pick_1b = document.getElementsByName('pick_1');
    var pick_2b = document.getElementsByName('pick_2');

    alert(pick_0b[0].value);
}
var pick_0b = ""
var pick_1b = ""
var pick_2b = ""

function inputs() {
    document.getElementsByName('pick_0');
    document.getElementsByName('pick_1');
    document.getElementsByName('pick_2');
}

alert(pick_0b[0].value);
// ==UserScript==
// @name       Result Reader
// @namespace  tarakore.com
// @version    1.0
// @description  Stupid description goes here.
// @match      http://www.(removedurl).com/game/* //Url removed because the site in question wouldn't want attention from this post.
// @copyright  2014+ Tarakore/Katiki
// @grant   GM_xmlhttpRequest
// @require       http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
// ==/UserScript==
// ==UserScript==
// @name         Result Reader
// @namespace    tarakore.com
// @version      1.0
// @description  Stupid description goes here.
// @match        http://www.(removedurl).com/game/* 
// @copyright    2014+ Tarakore/Katiki
// @grant        GM_xmlhttpRequest
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
// ==/UserScript==