I have data that I am trying to scrape and save to JSON but I'm getting this symbol "↵"
For example my data is this -
<span class="tracktime">06:21
- 15.26 mb</span>
I am trying to save the duration only using -
'duration': $(this).find('span[class="tracktime"]').text().trim().replace(/\↵/g, " ").trim().split(" ")[0]
but the data I am getting back is -
duration: "06:21↵-"
I have also tried this with no luck -
.replace(/\r\n/g, "")
Any help would be appreciated thanks!
Why not work with substr
?
let text = document.querySelector('.tracktime').textContent.trim().substr(0, 5); console.log(text);
<span class="tracktime">06:21 - 15.26 mb</span>
If all you want to achieve is replacing the new line, go like this:
let text = document.querySelector('.tracktime').textContent.trim().replaceAll('\n', ''); console.log(text);
<span class="tracktime">06:21 - 15.26 mb</span>
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.