<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GAS アーカイブ - Sheltie Garage Tech</title>
	<atom:link href="https://sheltie-garage.xyz/tech/category/gas/feed/" rel="self" type="application/rss+xml" />
	<link>https://sheltie-garage.xyz/tech/category/gas/</link>
	<description>テクノロジー関連の話題をまとめたブログです</description>
	<lastBuildDate>Sun, 02 Mar 2025 13:12:30 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>GASでスクレイピングする</title>
		<link>https://sheltie-garage.xyz/tech/2025/03/gas%e3%81%a7%e3%82%b9%e3%82%af%e3%83%ac%e3%82%a4%e3%83%94%e3%83%b3%e3%82%b0%e3%81%99%e3%82%8b/</link>
					<comments>https://sheltie-garage.xyz/tech/2025/03/gas%e3%81%a7%e3%82%b9%e3%82%af%e3%83%ac%e3%82%a4%e3%83%94%e3%83%b3%e3%82%b0%e3%81%99%e3%82%8b/#respond</comments>
		
		<dc:creator><![CDATA[monodon]]></dc:creator>
		<pubDate>Sun, 02 Mar 2025 13:12:29 +0000</pubDate>
				<category><![CDATA[GAS]]></category>
		<guid isPermaLink="false">https://sheltie-garage.xyz/tech/?p=1146</guid>

					<description><![CDATA[<p>かなり久しぶりのTechブログ書きたいことは色々あるんですが、なかなか書く時間が取れず久しぶりの更新となりました 業務でGASを使う機会が増えました 業務改善で「サーバー上にあるファイルを自動取得したい」という相談が来ま [&#8230;]</p>
<p>投稿 <a href="https://sheltie-garage.xyz/tech/2025/03/gas%e3%81%a7%e3%82%b9%e3%82%af%e3%83%ac%e3%82%a4%e3%83%94%e3%83%b3%e3%82%b0%e3%81%99%e3%82%8b/">GASでスクレイピングする</a> は <a href="https://sheltie-garage.xyz/tech">Sheltie Garage Tech</a> に最初に表示されました。</p>
]]></description>
										<content:encoded><![CDATA[
<p>かなり久しぶりのTechブログ<br>書きたいことは色々あるんですが、なかなか書く時間が取れず久しぶりの更新となりました</p>



<h2 class="wp-block-heading">業務でGASを使う機会が増えました</h2>



<p>業務改善で「サーバー上にあるファイルを自動取得したい」という相談が来ました<br>調べてみるとGASでスクレイピングしてURLを抽出できそうだったので、GASでスクレイピングしてみることにしました</p>



<h2 class="wp-block-heading">ライブラリ導入から実際のスクレイピングまで</h2>



<p>まずはパーサー(構文解析)の追加を行います<br>ライブラリの「+」ボタンをクリックし、以下のIDを入力して検索をクリックします</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>1Mc8BthYthXx6CoIz90-JiSzSafVnT6U3t0z_W3hLTAX5ek4w0G_EIrNw</code></pre></div>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="704" src="https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_001-1024x704.png" alt="" class="wp-image-1147" srcset="https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_001-1024x704.png 1024w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_001-300x206.png 300w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_001-768x528.png 768w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_001-1536x1057.png 1536w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_001-2048x1409.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="981" src="https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_002-1024x981.png" alt="" class="wp-image-1148" srcset="https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_002-1024x981.png 1024w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_002-300x287.png 300w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_002-768x736.png 768w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_002.png 1102w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>追加をクリックすると、以下のようにPaserが追加されます</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="549" src="https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_003-1024x549.png" alt="" class="wp-image-1149" srcset="https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_003-1024x549.png 1024w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_003-300x161.png 300w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_003-768x412.png 768w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_003-1536x823.png 1536w, https://sheltie-garage.xyz/tech/wp-content/uploads/2025/03/20250302_003.png 1888w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>以上で事前準備は完了です</p>



<h2 class="wp-block-heading">スクレイピングしてみる</h2>



<p>このライブラリは非常にシンプルで「fromメソッド、toメソッドで指定された範囲の文字列を取得する」という動作をします<br>サンプルプログラムは以下になります</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>function myFunction() {
  // URLを指定してスクレイピングする場合
  // var url = &quot;https://example.com&quot;;
  // var content = UrlFetchApp.fetch(url).getContentText(&quot;UTF-8&quot;);

var content = &#39;&lt;!DOCTYPE html&gt;&#39; +
  &#39;&lt;html&gt;&#39; +
  &#39;&lt;head&gt;&#39; +
  &#39;  &lt;meta charset=&quot;UTF-8&quot;&gt;&#39; +
  &#39;  &lt;title&gt;サンプルページ&lt;/title&gt;&#39; +
  &#39;&lt;/head&gt;&#39; +
  &#39;&lt;body&gt;&#39; +
  &#39;  &lt;h1&gt;見出し1&lt;/h1&gt;&#39; +
  &#39;  &lt;p&gt;これはサンプルのHTMLページです。&lt;/p&gt;&#39; +
  &#39;  &lt;div id=&quot;content&quot;&gt;&#39; +
  &#39;    &lt;p&gt;ここはコンテンツエリアです。&lt;/p&gt;&#39; +
  &#39;    &lt;p&gt;もう一つの段落です。&lt;/p&gt;&#39; +
  &#39;  &lt;/div&gt;&#39; +
  &#39;  &lt;footer&gt;&#39; +
  &#39;    &lt;small&gt;© 2025 サンプルサイト&lt;/small&gt;&#39; +
  &#39;  &lt;/footer&gt;&#39; +
  &#39;&lt;/body&gt;&#39; +
  &#39;&lt;/html&gt;&#39;;

  
  // ------------------------
  // build() を利用して、&lt;title&gt; タグの中身を1回だけ抽出
  var titleText = Parser.data(content)
                        .from(&quot;&lt;title&gt;&quot;)
                        .to(&quot;&lt;/title&gt;&quot;)
                        .build();
  Logger.log(&quot;タイトル: &quot; + titleText);
  
  // ------------------------
  // iterate() を利用して、すべての &lt;p&gt; タグの中身を抽出
  var paragraphs = Parser.data(content)
                         .from(&quot;&lt;p&gt;&quot;)
                         .to(&quot;&lt;/p&gt;&quot;)
                         .iterate();
  
  Logger.log(&quot;抽出された段落の数: &quot; + paragraphs.length);
  paragraphs.forEach(function(text, index) {
    Logger.log(&quot;段落 &quot; + (index + 1) + &quot;: &quot; + text);
  });
}
</code></pre></div>



<p>from-toメソッドで抽出範囲を指定し、build(1つだけ取得)、itearte(該当するすべてを取得)を指定するだけです<br>もちろん、buildやiterateで取得した文字列に対して、更にfrom-toで絞り込みを行うこともできます</p>



<h2 class="wp-block-heading">GASの限界</h2>



<p>今回紹介したライブラリを利用することでGASでもスクレイピングを行うことができます<br>ただし、seleniumなどのヘッドレスブラウザのような硬度なスクレイピングは行えないため、例えばページが動的に変化するようなページはGASだけでは対応できません</p>



<h2 class="wp-block-heading">以上</h2>



<p>簡単ですが、GASでスクレイピングを行う方法を紹介しました<br>これを使えば毎日チェックしているWebページの自動化などが行えるかもしれませんね</p>


<div id="rinkerid1150" class="yyi-rinker-contents  yyi-rinker-postid-1150 yyi-rinker-img-m yyi-rinker-catid-22 ">
	<div class="yyi-rinker-box">
		<div class="yyi-rinker-image">
							<a href="https://af.moshimo.com/af/c/click?a_id=3394378&#038;p_id=54&#038;pc_id=54&#038;pl_id=616&#038;url=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2FGoogle%2BApp%2BScript%2F%3Ff%3D1%26grp%3Dproduct" rel="nofollow"><img loading="lazy" decoding="async" src="https://thumbnail.image.rakuten.co.jp/@0_mall/book/cabinet/4741/9784798064741_1_4.jpg?_ex=128x128" width="128" height="128" class="yyi-rinker-main-img" style="border: none;"></a><img loading="lazy" decoding="async" src="https://i.moshimo.com/af/i/impression?a_id=3394378&amp;p_id=54&amp;pc_id=54&amp;pl_id=616" width="1" height="1" style="border:none;">					</div>
		<div class="yyi-rinker-info">
			<div class="yyi-rinker-title">
									<a href="https://af.moshimo.com/af/c/click?a_id=3394378&#038;p_id=54&#038;pc_id=54&#038;pl_id=616&#038;url=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2FGoogle%2BApp%2BScript%2F%3Ff%3D1%26grp%3Dproduct" rel="nofollow">詳解！ Google Apps Script完全入門 ［第3版］ ～GoogleアプリケーションとGoogle Workspaceの最新プログラミングガイド～ [ 高橋宣成 ]</a><img loading="lazy" decoding="async" src="https://i.moshimo.com/af/i/impression?a_id=3394378&amp;p_id=54&amp;pc_id=54&amp;pl_id=616" width="1" height="1" style="border:none;">							</div>
			<div class="yyi-rinker-detail">
							<div class="credit-box">created by&nbsp;<a href="https://oyakosodate.com/rinker/" rel="nofollow noopener" target="_blank" >Rinker</a></div>
										<div class="price-box">
							<span title="" class="price">¥2,860</span>
															<span class="price_at">(2026/04/20 10:59:20時点&nbsp;楽天市場調べ-</span><span title="このサイトで掲載されている情報は当サイトの作成者により運営されています。価格、販売可能情報は、変更される場合があります。購入時に楽天市場店舗（www.rakuten.co.jp）に表示されている価格がその商品の販売に適用されます。">詳細)</span>
																	</div>
						</div>
						<ul class="yyi-rinker-links">
																                    <li class="amazonlink">
						<a href="https://www.amazon.co.jp/gp/search?ie=UTF8&amp;keywords=Google+App+Script&amp;tag=monodon-22&amp;index=blended&amp;linkCode=ure&amp;creative=6339" rel="nofollow" class="yyi-rinker-link">Amazon</a>					</li>
													<li class="rakutenlink">
						<a href="https://af.moshimo.com/af/c/click?a_id=3394378&amp;p_id=54&amp;pc_id=54&amp;pl_id=616&amp;url=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2FGoogle%2BApp%2BScript%2F%3Ff%3D1%26grp%3Dproduct" rel="nofollow" class="yyi-rinker-link">楽天市場</a><img loading="lazy" decoding="async" src="https://i.moshimo.com/af/i/impression?a_id=3394378&amp;p_id=54&amp;pc_id=54&amp;pl_id=616" width="1" height="1" style="border:none;">					</li>
													<li class="yahoolink">
						<a href="https://af.moshimo.com/af/c/click?a_id=3442618&amp;p_id=1225&amp;pc_id=1925&amp;pl_id=18502&amp;url=https%3A%2F%2Fshopping.yahoo.co.jp%2Fsearch%3Fp%3DGoogle%2BApp%2BScript" rel="nofollow" class="yyi-rinker-link">Yahooショッピング</a><img loading="lazy" decoding="async" src="https://i.moshimo.com/af/i/impression?a_id=3442618&amp;p_id=1225&amp;pc_id=1925&amp;pl_id=18502" width="1" height="1" style="border:none;">					</li>
				                											</ul>
					</div>
	</div>
</div>


<div id="rinkerid1151" class="yyi-rinker-contents  yyi-rinker-postid-1151 yyi-rinker-img-m yyi-rinker-catid-22 ">
	<div class="yyi-rinker-box">
		<div class="yyi-rinker-image">
							<a href="https://af.moshimo.com/af/c/click?a_id=3394378&#038;p_id=54&#038;pc_id=54&#038;pl_id=616&#038;url=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2F%25E3%2582%25B9%25E3%2583%2597%25E3%2583%25AC%25E3%2583%2583%25E3%2583%2589%25E3%2582%25B7%25E3%2583%25BC%25E3%2583%2588%2F%3Ff%3D1%26grp%3Dproduct" rel="nofollow"><img loading="lazy" decoding="async" src="https://thumbnail.image.rakuten.co.jp/@0_mall/book/cabinet/5883/9784839975883.jpg?_ex=128x128" width="128" height="128" class="yyi-rinker-main-img" style="border: none;"></a><img loading="lazy" decoding="async" src="https://i.moshimo.com/af/i/impression?a_id=3394378&amp;p_id=54&amp;pc_id=54&amp;pl_id=616" width="1" height="1" style="border:none;">					</div>
		<div class="yyi-rinker-info">
			<div class="yyi-rinker-title">
									<a href="https://af.moshimo.com/af/c/click?a_id=3394378&#038;p_id=54&#038;pc_id=54&#038;pl_id=616&#038;url=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2F%25E3%2582%25B9%25E3%2583%2597%25E3%2583%25AC%25E3%2583%2583%25E3%2583%2589%25E3%2582%25B7%25E3%2583%25BC%25E3%2583%2588%2F%3Ff%3D1%26grp%3Dproduct" rel="nofollow">ブラウザだけで学べる Googleスプレッドシート プログラミング入門 [ 掌田津耶乃 ]</a><img loading="lazy" decoding="async" src="https://i.moshimo.com/af/i/impression?a_id=3394378&amp;p_id=54&amp;pc_id=54&amp;pl_id=616" width="1" height="1" style="border:none;">							</div>
			<div class="yyi-rinker-detail">
							<div class="credit-box">created by&nbsp;<a href="https://oyakosodate.com/rinker/" rel="nofollow noopener" target="_blank" >Rinker</a></div>
										<div class="price-box">
							<span title="" class="price">¥2,618</span>
															<span class="price_at">(2026/04/20 10:59:20時点&nbsp;楽天市場調べ-</span><span title="このサイトで掲載されている情報は当サイトの作成者により運営されています。価格、販売可能情報は、変更される場合があります。購入時に楽天市場店舗（www.rakuten.co.jp）に表示されている価格がその商品の販売に適用されます。">詳細)</span>
																	</div>
						</div>
						<ul class="yyi-rinker-links">
																                    <li class="amazonlink">
						<a href="https://www.amazon.co.jp/gp/search?ie=UTF8&amp;keywords=%E3%82%B9%E3%83%97%E3%83%AC%E3%83%83%E3%83%89%E3%82%B7%E3%83%BC%E3%83%88&amp;tag=monodon-22&amp;index=blended&amp;linkCode=ure&amp;creative=6339" rel="nofollow" class="yyi-rinker-link">Amazon</a>					</li>
													<li class="rakutenlink">
						<a href="https://af.moshimo.com/af/c/click?a_id=3394378&amp;p_id=54&amp;pc_id=54&amp;pl_id=616&amp;url=https%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2F%25E3%2582%25B9%25E3%2583%2597%25E3%2583%25AC%25E3%2583%2583%25E3%2583%2589%25E3%2582%25B7%25E3%2583%25BC%25E3%2583%2588%2F%3Ff%3D1%26grp%3Dproduct" rel="nofollow" class="yyi-rinker-link">楽天市場</a><img loading="lazy" decoding="async" src="https://i.moshimo.com/af/i/impression?a_id=3394378&amp;p_id=54&amp;pc_id=54&amp;pl_id=616" width="1" height="1" style="border:none;">					</li>
													<li class="yahoolink">
						<a href="https://af.moshimo.com/af/c/click?a_id=3442618&amp;p_id=1225&amp;pc_id=1925&amp;pl_id=18502&amp;url=https%3A%2F%2Fshopping.yahoo.co.jp%2Fsearch%3Fp%3D%25E3%2582%25B9%25E3%2583%2597%25E3%2583%25AC%25E3%2583%2583%25E3%2583%2589%25E3%2582%25B7%25E3%2583%25BC%25E3%2583%2588" rel="nofollow" class="yyi-rinker-link">Yahooショッピング</a><img loading="lazy" decoding="async" src="https://i.moshimo.com/af/i/impression?a_id=3442618&amp;p_id=1225&amp;pc_id=1925&amp;pl_id=18502" width="1" height="1" style="border:none;">					</li>
				                											</ul>
					</div>
	</div>
</div>
<p>投稿 <a href="https://sheltie-garage.xyz/tech/2025/03/gas%e3%81%a7%e3%82%b9%e3%82%af%e3%83%ac%e3%82%a4%e3%83%94%e3%83%b3%e3%82%b0%e3%81%99%e3%82%8b/">GASでスクレイピングする</a> は <a href="https://sheltie-garage.xyz/tech">Sheltie Garage Tech</a> に最初に表示されました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sheltie-garage.xyz/tech/2025/03/gas%e3%81%a7%e3%82%b9%e3%82%af%e3%83%ac%e3%82%a4%e3%83%94%e3%83%b3%e3%82%b0%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
