After entering a page and pressing control + shift + k Iam trying to write an JavaScript extraction code that extracts the date, username, and text. In the console There are too many to copy and paste and I want to extract this to a txt file. This currently lays in body of the html hidden. Iam looking for output like this:
little ricky 2021-06-12T23:58:55.522Z Enjoy. I was just there.
I tried:
console.log(document.getElementsByClassName("header-23xsNx").text)
which return undefined.
Heres the html username and date Iam looking for:
<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>
Heres where the text portion is:
<div class="markup-2BOw-j messageContent-2qWWxC">Enjoy. I was just there.</div>
Try this:
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.