问题
On Reddit, people can post comments that get upvotes and downvotes. This information is not readily accessible on the page itself, so it seems that something like an API is used to gather this information.
I found this script that does this, but am unable to determine where in the script it pulls this information from. Could someone point me to the relevant line where the script gets the data from?
回答1:
Each comment has data
attributes:
<div class="thing id-t1_c4upmtm odd comment " onclick="click_thing(this)" data-fullname="t1_c4upmtm" data-ups="646" data-downs="83">
Reddit's HTML structure is really hard to follow so figure out a way to get from the comment ID to the element which contains this stuff.
回答2:
That script uses GM_xmlhttpRequest()
to fetch the JSON data for the given: comments or user page.
The data returned by GM_xmlhttpRequest()
, is accessed in the line:
var jsonText = response.responseText,data;
and then parsed with the script's processTree()
function. There is not really one line; much of the script is required for this functionality.
On the comments pages, it seems that using the API is the only way to get up-votes and down-votes separately.
来源:https://stackoverflow.com/questions/10844664/on-reddit-how-do-scripts-get-the-number-of-upvotes-and-downvotes-for-a-comment