[英]How to extract text and user names from a chat in using javascript console?
進入頁面並按下 control + shift + k 后,我試圖編寫一個提取日期、用戶名和文本的 JavaScript 提取代碼。 在控制台中有太多要復制和粘貼的內容,我想將其提取到 txt 文件中。 這目前隱藏在 html 的主體中。 我正在尋找這樣的 output:
little ricky 2021-06-12T23:58:55.522Z Enjoy. I was just there.
我試過了:
console.log(document.getElementsByClassName("header-23xsNx").text)
返回未定義。
這是我正在尋找的 html 用戶名和日期:
<h2 class="header-23xsNx"><span class="headerText-3Uvj1Y"><span class="username-1A8OIy desaturateUserColors-1gar-1 clickable-1bVtEA"
aria-controls="popout_509" aria-expanded="false" style="color: rgb(241, 196, 15);" role="button" tabindex="0">
little ricky</span></span><span class="timestamp-3ZCmNB timestampInline-yHQ6fX">
<time aria-label="Today at 6:58 PM" datetime="2021-06-12T23:58:55.522Z">
<i class="separator-2nZzUB" aria-hidden="true"> —
</i>Today at 6:58 PM</time></span></h2>
這里是文本部分:
<div class="markup-2BOw-j messageContent-2qWWxC">Enjoy. I was just there.</div>
嘗試這個:
var constructed = document.querySelector('.username-1A8OIy').innerText+' '+document.querySelector('time').getAttribute('datetime')+' '+document.querySelector('.messageContent-2qWWxC').innerText; console.log(constructed);
<h2 class="header-23xsNx"><span class="headerText-3Uvj1Y"><span class="username-1A8OIy desaturateUserColors-1gar-1 clickable-1bVtEA" aria-controls="popout_509" aria-expanded="false" style="color: rgb(241, 196, 15);" role="button" tabindex="0"> little ricky</span></span><span class="timestamp-3ZCmNB timestampInline-yHQ6fX"> <time aria-label="Today at 6:58 PM" datetime="2021-06-12T23:58:55.522Z"> <i class="separator-2nZzUB" aria-hidden="true"> — </i>Today at 6:58 PM</time></span></h2> <div class="markup-2BOw-j messageContent-2qWWxC">Enjoy. I was just there.</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.