3 回答

TA貢獻2036條經驗 獲得超8個贊
嘗試使用cheerio(專為服務器設計的核心 jQuery 實現)
axios
.get(url)
.then(response => {
const $ = cheerio.load(response.data);
const image = $('img')
$("img").each((i, elem) => {
{
...
})
...
})

TA貢獻1844條經驗 獲得超8個贊
再見,看這個例子:
console.log($( "div.col" ).text())
console.log($( "img" ).attr('src'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="example">
<title>Example</title>
</head>
<body>
<div class="container">
<div class="row">
<img src="example.png" alt="example">
<div class="col">Example</div>
</div>
</div>
</body>
</html>
我得到了 div 的內部col
文本$( "div.col" ).text()
。
要獲得一個屬性(例如) src
,img
我已經完成了$( "img" ).attr('src')

TA貢獻1818條經驗 獲得超11個贊
如果您將響應添加到文檔,然后嘗試獲取事件,那么您可以嘗試以下方法
$('body').on('click', '.col', function(){
// do your work
})
如果您想即時選擇任何元素,請使用以下方法
$(response).find('.col')
添加回答
舉報