---
# System prepended metadata

title: 使用類JQuery 抓取目標DOM，Cheerio for GAS
tags: [GoogleAppScript]

---

# 使用類JQuery 抓取目標DOM，Cheerio for GAS 
[cheerio 程式庫 github](https://github.com/tani/cheeriogs)

Script ID: 1ReeQ6WO8kKNxoaA_O0XEQ589cIrRvEBA9qcWpNqdOP17i47u6N9M5Xh0

## 新增cheerio程式庫
左邊側邊欄資料庫 + ，用Script ID搜尋程式庫並新增
![](https://i.imgur.com/DRhNWG0.png)

<pre><code>
code:

const url = '目標網址';
//mothod get 網址
let response = UrlFetchApp.fetch(url);

//取得目標網址HTML
let $ = Cheerio.load(response.getContentText(),{decodeEntities:false})

//找目標DOM > 屬性
let test = $('.sensitive-content > a > img').first();
let imgUrl = test.attr("data-src");
</code></pre>

### 然後就抓到要抓的東西惹....