[英]Streamer w. ~5k followers. Trying to scrape data from a table using JS?
我是中型流媒體,最近從StreamLabs獲得了忠誠度系統,其中包括每個用戶在流中累積的積分。 但是,我無法使用自己的JavaScript來定制積分系統並添加新功能,因此我想將另一個開源twitch bot(Phantombot)與StreamLabs系統結合使用。 我的觀眾也非常喜歡StreamLabs疊加層,因此我不能只走純Phantombot路線。
我有1,000多個用戶,每個用戶都有自己的積分需要轉移。 StreamLabs沒有提供一種干凈的方法來導出包含用戶及其點值的excel文檔。 我檢查了列出所有要點的頁面,其結構如下:
<tbody>
<tr>
<td class="table_name"> String </td> <!-- The name of the user -->
<td class="table__message"> Number </td> <!-- The user's amount of points -->
<td class="table__controls">
<div class="pane-dropdown">
<a class="pane-dropdown__toggle"> <!-- The cog opens the dropdown list -->
<span>
<i class="fa fa-cog"> <!-- There she is. -->
::before
</i>
</span>
</a>
<div class="pane-dropdown__menu" style="display: none;">
<span>
<ul class="pane-dropdown__list">
<li>
<a class="pane-dropdown__link">Edit Points</a>
<li>
<li>
<a class="pane-dropdown__link warn">Block User</a>
</li>
<li>
<a class="pane-dropdown__link warn">Reset Points</a>
</li>
</ul>
</span>
</div>
</div>
</td>
</tr>
<!-- More table rows for each user -->
這是頁面外觀的鏈接:
有沒有辦法讓我循環瀏覽每個頁面,為每個用戶獲取要點,然后將信息以有意義的格式(例如excel文檔)放置?
我知道我主要自學的基本JavaScript,並且具有很好的直覺-但是像這樣的項目完全超出了我的技能范圍。 我正在考慮使用for循環將每個用戶的對象推送到數組,並為點和屬性命名,然后將這兩個屬性全部導出到.csv文檔。 但是,我不知道該怎么做,或者是否有可能(但是如果是冰棒,則有可能),所以我認為這是有可能的。 任何朝着正確方向前進的人將不勝感激。
我的想法是,在構建腳本時,類table_name和table__message可能是一個不錯的起點-有任何指導嗎?
看來Streamlabs API有幾種與Points交互的選項。
瀏覽示例,您可能正在尋找“組獲取點”:
var data = JSON.stringify(false);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://streamlabs.com/api/v1.0/points/group_get_points?access_token=access_token&channel=channel&usernames=usernames");
xhr.send(data);
這將導致一系列帶有其分數的用戶,類似於:
[
{
username: "sunny601",
points: 94
},
{
username: "sunny602",
points: 103
}
]
在瀏覽器端,您可以遍歷所有tr ,並獲得它們的第一個和第二個孩子的值:
const result =
[...document.getElementsByTagName("tr")]
.map(el => [ el.children[0].textContent, el.children[1].textContent ])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.