故事
我正在尝试构建一个pewdiepie vs T系列机器人,该机器人每小时将来自youtube api的当前子计数推到Twitter帐户。 我是编程的新手,现在我想知道如何获取这个html子计数对象并将其作为变量传递到我的js文件中,这样我就可以实际发送该子计数而不是仅在网页上发送。那有道理吗?
正在使用什么?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta http-equiv="X-UA-Compatible"content="ie=edge">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/ materialize/1.0.0-rc.2
/css/materialize.min.css">
<title>SUBSCRIBE TO PEWDIEPIE!</title>
</head>
<body>
<nav class="black">
<div clsss="nav-wrapper">
<div class="container">
<a href="#!" class="brand-logo">SUBSCRIBE TO PEWDIEPIE</a>
</div>
</div>
</nav>
<br>
<section>
<div class="container">
<div class="left w50">
<br>
<div id="content_pewds">
<div class="row">
<div class="col s6">
<form id="channel_form">
<div class="input-field">
<h1>PEWDIEPIE</h1>
<h3>Current Subscribers</h3>
<h1 id="yt-countPewds"></h1>
<script>
function getJSON(response) {
var subCount =
response.items[0].statistics.subscriberCount;
document.getElementById('yt-countPewds').innerHTML = subCount;
}
</script>
<script src="https://www.googleapis.com/youtube/v3/channelspart=statistics&id=UC-lHJZR3Gqxm24_Vd_AJ5Yw&key=keyc&callback=getJSON"></script>
<button id="subBtn" class="btn red lighten ">SUBSCRIBE</button>
</div>
</form>
</div>
<div id="channel_data" class="col s6"></div>
</div>
<div class="row" id="video_container"></div>
</div>
</div>
</section>
</div>
这是我的JS Bot文件
//Twit Package
var Twit = require('twit');
// Twit API Keys Imported From config.js File
var config = require('./config');
// Twit Package Keys Object
var T = new Twit(config)
setInterval(tweetIt, 1000*10)
//so this is what i would like to acomplish with the program
tweetIt('pewds: '+ pewdsTotalSubs + 'tseries: '+ tseriesTotalSubs)
function tweetIt(txt){
var tweet = {
status: txt
}
T.post('statuses/update', tweet, tweeted);
function tweeted(err, data, response) {
if (err) {
console.log("Something Went Wrong!")
} else {
console.log("It Worked!")
}
}
}