<?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>資料 - HJs 找樂趣</title>
	<atom:link href="https://huijou.com/tag/%e8%b3%87%e6%96%99/feed/" rel="self" type="application/rss+xml" />
	<link>https://huijou.com/tag/資料/</link>
	<description>HJs 紀錄美好生活,一群有著同樣興趣志向的夥伴們成立的夢想空間,分享你我生活中會遇見的人事物,共享 旅遊、美食、科技 資源,同步最新大數據訊息 ！</description>
	<lastBuildDate>Thu, 15 Apr 2021 04:15:17 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://huijou.com/wp-content/uploads/2021/04/logo-1-150x150.png</url>
	<title>資料 - HJs 找樂趣</title>
	<link>https://huijou.com/tag/資料/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>[python 爬蟲寶典] 爬蟲入門、爬蟲進階資料採集</title>
		<link>https://huijou.com/python-request/</link>
					<comments>https://huijou.com/python-request/#comments</comments>
		
		<dc:creator><![CDATA[troy801125]]></dc:creator>
		<pubDate>Thu, 15 Apr 2021 04:15:07 +0000</pubDate>
				<category><![CDATA[科技知識]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[大數據]]></category>
		<category><![CDATA[爬蟲]]></category>
		<category><![CDATA[資料]]></category>
		<guid isPermaLink="false">https://huijou.com/?p=157</guid>

					<description><![CDATA[<p>爬蟲經典package還是requests的呼叫功能，目前在各大網站上去請求資料回傳速度是最快的，如果網站有做一些反爬蟲的方法，可以使用header中User-...</p>
<p class="read-more"><a class="btn btn-default" href="https://huijou.com/python-request/"> Read More<span class="screen-reader-text">  Read More</span></a></p>
<p>這篇文章 <a href="https://huijou.com/python-request/">[python 爬蟲寶典] 爬蟲入門、爬蟲進階資料採集</a> 最早出現於 <a href="https://huijou.com">HJs 找樂趣</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>爬蟲經典package還是requests的呼叫功能，目前在各大網站上去請求資料回傳速度是最快的，如果網站有做一些反爬蟲的方法，可以使用header中User-Agent去訪問請求資料回來。如果需要破解驗證碼的話，可以採用selenium來仿真人去瀏覽器獲得資料，接下來部分我會手把手教你如何在網路世界中，抓取你想得到的資訊 (切記勿盜取商業資料或是做違法行為) 。</p>



<figure class="wp-block-image is-resized is-style-rounded"><img fetchpriority="high" decoding="async" src="https://lh4.googleusercontent.com/cbH3tz98AanwLU9_6Vj7BuRl7rYIKms6LAc3c5w6tWRuvzboeUMd-_nqpyyynyvQ6_uLCOn9xFtPxJesV-PiaKuH9aG5n1d0mKvnysjW5YEpOGN81T7nVGpL0uKNW_2X7qwVEzp1" alt="" width="839" height="425"/></figure>



<p>(圖為google網路上抓取)</p>



<p>基本上通過以上擷取方式可以解析資料</p>



<figure class="wp-block-image is-resized"><img decoding="async" src="https://lh3.googleusercontent.com/vu2ihuk0T1HkChjAai9qn3E2Q_wriK-nuwm_acvQkwqgITmNP-bKa-JkTPnMgo7Rrb1J5RVnEV72rgbQWp1QgRmHqQRCJYX_69xQ2xA8DaEeTdlQcgrk84YlKGEyDgQzDtue1FNg" alt="" width="838" height="423"/></figure>



<p>(圖為google網路上抓取)&nbsp; (如果有擋爬蟲可以採用selenium抓取)</p>



<p>這邊可以先安裝 python 分析專用編輯器&nbsp; <a href="https://huijou.com/python/">https://huijou.com/python/</a></p>



<p>這邊附上 pip 安裝網址給大家去安裝</p>



<p>request : <a href="https://pypi.org/project/requests/">https://pypi.org/project/requests/</a></p>



<p>selenium : <a href="https://pypi.org/project/selenium/">https://pypi.org/project/selenium/</a></p>



<p><strong>官網上可以下載任何 package </strong></p>



<figure class="wp-block-image is-resized"><img decoding="async" src="https://lh6.googleusercontent.com/_hWW_nbBZwUKqocxNGyIgeKAAq1Y8sfpJAAulnf-LgW0tCFYAsrKCXRkOqWGEpCrcOn0IPA8k7sK1UZZVMpAW5uyYDDgnUk_PKL6nQNOupbuyWjxfayCmU2wmMhnI_0l6lhID8ld" alt="" width="838" height="649"/></figure>



<p>這邊示範為&nbsp; <strong>個股日成交資訊</strong></p>



<p>證交所在政府開放資料平台上提供了一個資料集個股日成交資訊，這裡面的資料會每日更新，並且只保留最新的資料。</p>



<figure class="wp-block-image"><img decoding="async" src="https://lh5.googleusercontent.com/slRa8hHPJ44Ep200MchLOLAjtFY2dISNXlRJi8EXONGN0ERSU5oZSFYCVFbxCPTWHfOEJ5h1rN9mOggYnt7BIJISxQqtAkJU6p8f_w520ICXWyVJbLDUB2YdTBP7UnHgWIQfRxRN" alt=""/></figure>



<p>第一步抓取 台灣證券交易所資料</p>



<p>開啟 python &#8211; jupyter 請求api的網址去呼叫對方，傳送data回來</p>



<figure class="wp-block-image"><img decoding="async" src="https://lh6.googleusercontent.com/eybcAgE9-Z-M14IF5P0jZcOEO01Z4BcA4l1G_WMcxTUllDtJZSou-UAXc9V2EwRS7vwozSyj2L_9cK757-9U40nMUgknr5mkZKaDdtonkr_K3wq6WIiRmTjzdQ7Pb0gdzJyMEUqa" alt=""/></figure>



<p>抓下後就可以看到 1127列 10行 的 datafrme 型式資料</p>



<figure class="wp-block-image"><img decoding="async" src="https://lh5.googleusercontent.com/i_rMCfMzzC5kqPdtyT1CDPBpdUXPWJgCH2IEa_kIx8DXsi8VkTX5lNb0qufvPdNcqmhNEh1V2Aphp7AZmCYnJXE2SVJ8m3rWEsosv0t4DzznZt11x5wFyiJUcPRNT-gksv0iaIAS" alt=""/></figure>



<p><strong>程式碼雙手奉上 </strong></p>



<pre class="wp-block-code"><code>#載入 package
import requests
import pandas as pd

# 透過證交所API抓取資料
url = 'http://www.twse.com.tw/exchangeReport/STOCK_DAY_ALL?response=open_dat'
tt = requests.get(link)
df_data = pd.DataFrame(tt.json()&#91;'data'])

# 修改欄位名稱
df_data.columns = &#91;'SECURITY_CODE', 'NAME', 'VOLUME', 'AMOUNT', 'OPEN','HIGH', 'LOW', 'CLOSE', 'PRICE_CHANGE', 'TRANSACTION']</code></pre>



<p>接下來就可以隨心所欲的使用它溜 !!</p>



<p><strong>下篇會教導 selenium 進階篇 反爬蟲處理 </strong></p>



<p><a href="https://huijou.com">喜歡我的文章可以點擊這觀看更多</a></p>
<p>這篇文章 <a href="https://huijou.com/python-request/">[python 爬蟲寶典] 爬蟲入門、爬蟲進階資料採集</a> 最早出現於 <a href="https://huijou.com">HJs 找樂趣</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://huijou.com/python-request/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
