[英]JS | Node.js - Divide a string into arguments considering quotation marks
[英]Is there a way to remove quotation marks (Node.js Web Application)
代碼:
async function watchAnime(episode_id) {
res = await axios.get(`https://www1.gogoanime.cm/${episode_id}`)
const body = await res.data;
$ = cheerio.load(body)
src=$('div.play-video > iframe').attr('src')
iframe_result = src
return await (iframe_result)
}
Output:
"//gogoplay1.com/streaming.php?id=MTU1MzEy&title=B%3A+The+Beginning+Succession+%28Dub%29+Episode+6"
圖片: https://i.stack.imgur.com/yeM0C.png
所以它有辦法從 output URL 中刪除引號?
要獲取沒有第一個和最后一個字符的字符串str
的副本:
const newString = str.substring(1, str.length-1)
所以:
const str = `"foo"`
console.log(str.substring(1, str.length-1)) // output foo
您可以使用.replace()
src.replace(/['"]+/g, '')
所以在你的情況下
async function watchAnime(episode_id) {
res = await axios.get(`https://www1.gogoanime.cm/${episode_id}`)
const body = await res.data;
$ = cheerio.load(body)
let src = $('div.play-video > iframe').attr('src')
let iframe_result = src.replace(/['"]+/g, '')
return await (iframe_result)
}
您可以嘗試像這樣使用.replace function :
const string = `i am' abc `;
console.log(string.replace("'", ''))
控制台:我是abc
你可以閱讀更多關於這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.