tag:blogger.com,1999:blog-89013942070767196382024-02-07T18:23:32.326-08:00Python 教學筆記本本網站主要是以python教學為主,如果內容有不妥的地方也歡迎提出。
目前擔任 python 程式設計工程師的工作,歡迎大家提出各種問題王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.comBlogger56125tag:blogger.com,1999:blog-8901394207076719638.post-69705874853290358892020-04-08T21:44:00.000-07:002020-04-08T21:45:59.416-07:00Anaconda 常用指令教學<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3R_XNNeLcVaLel7BKW0jZaPn1qwkEDTun4j5ivIRCSBLhWQvHyYKWqdBlppI9tQfLc4eAv5w14Lt9ZA3TLXXBwcYE-Mo5MB62KLCyYZTSGFYlAUFi35HgmwSaNPy-rhbbiHLFm6znaS8/s1600/anaconda.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="350" data-original-width="700" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3R_XNNeLcVaLel7BKW0jZaPn1qwkEDTun4j5ivIRCSBLhWQvHyYKWqdBlppI9tQfLc4eAv5w14Lt9ZA3TLXXBwcYE-Mo5MB62KLCyYZTSGFYlAUFi35HgmwSaNPy-rhbbiHLFm6znaS8/s1600/anaconda.png" /></a></div>
<br />
<h2 class="heading1" style="background-color: white; border-bottom-color: rgb(207, 202, 202); border-bottom-style: dashed; border-width: 0px 0px 1px; color: #50317b; font-family: "roboto condensed", arial, sans-serif; font-size: 26px; letter-spacing: -0.5px; line-height: 34px; margin: 45px 0px 18px; opacity: 1; outline: 0px; padding: 0px 0px 4px; transition: all 0.24s ease-in-out 0s; vertical-align: baseline; visibility: visible;">
Anaconda 教學</h2>
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"># Anaconda 常用指令
# 查看版本號
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">conda –V</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# 更新 conda 包的版本
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">conda update conda</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# 查看建立的虛擬環境的數量
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">conda env list</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# 建立虛擬環境並指定 python 版本
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">conda create --name myenv python=3.5</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# 啟動虛擬環境(Windows)
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">activate myenv</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# 啟動虛擬環境(Linux)
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">source activate myenv</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# 安裝 library (可用 pip)
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">conda install numpy</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# 離開虛擬環境(Windows)
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">deactivate
</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# 離開虛擬環境(Linux)
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">source deactivate</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# 移除虛擬環境
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">conda env remove --name myenv</span></pre>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-20304560976102019192020-03-01T03:25:00.001-08:002020-03-01T03:25:27.952-08:00Ubuntu 16 網路連線中斷、撥接<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGzfjS4TUDYcce_KhVyZKijwBLcDhtQjR_6T9B3Q4KzKq3oRoawriR5bujmgcMp7ufhpWWlWTdSSzHQJm6oAZNxwWHu0qfo_5A4MVGoBqw0COXwhQzhOc62Ws5vBgvtLY41QEmnfgavA0/s1600/Ubuntu.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="479" data-original-width="718" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGzfjS4TUDYcce_KhVyZKijwBLcDhtQjR_6T9B3Q4KzKq3oRoawriR5bujmgcMp7ufhpWWlWTdSSzHQJm6oAZNxwWHu0qfo_5A4MVGoBqw0COXwhQzhOc62Ws5vBgvtLY41QEmnfgavA0/s640/Ubuntu.jpg" width="640" /></a></div>
<br />
<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); color: #757575; font-family: monospace, monospace; line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="font-size: large;"><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace;"># 安裝網路工具</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace;">
sudo apt install net-tools
sudo apt-get install pppoeconf
</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace;"># 環境設定</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace;">
sudo pppoeconf
</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace;"># 中斷撥接連線</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace;">
sudo poff -a
</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace;"># 手動撥接</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace;">
sudo pon dsl-provider</span></span></pre>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-7140971050691100642020-01-03T20:48:00.002-08:002020-03-01T03:27:26.216-08:00遇見 ImportError: No module named PIL 解決辦法<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8MRZtYuS9oVfv3sCu5uPjUFkMfD5C6bCOiGomtcpNpJG9NHq1CXrHVpw8aIcgOYCnba2djTECmQ5C8G8hEXpZ63OJVaPaXb9Ww4pOf1B7D8hCjmHRZPuO2h9KcSGz3wNE3czyll1ukdA/s1600/unnamed.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="288" data-original-width="512" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8MRZtYuS9oVfv3sCu5uPjUFkMfD5C6bCOiGomtcpNpJG9NHq1CXrHVpw8aIcgOYCnba2djTECmQ5C8G8hEXpZ63OJVaPaXb9Ww4pOf1B7D8hCjmHRZPuO2h9KcSGz3wNE3czyll1ukdA/s640/unnamed.png" width="640" /></a></div>
<span style="font-size: large;"><b><br /></b></span>
<span style="font-size: large;"><b><br /></b></span>
<span style="font-size: large;"><b>會發生這種錯誤的原因,主要是因為你沒安裝到 Pillow 此模組,</b></span><b style="font-size: x-large;">只要在你的終端機輸入以下指令就可以解決你所遇見到的錯誤訊息了</b><br />
<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">pip </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">install Pillow
</span></pre>
<br />
<span style="font-size: large;"><b>希望我的文章有幫助到你在 coding 時所遇見的問題</b></span>王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-66055432527757393272020-01-02T06:34:00.003-08:002020-01-03T19:02:17.826-08:00pytesseract windows 安裝教學<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr90lPwJQQKCDH5U5EmQyTnQh_UzHQg5GbnvkeFXUXuGjULwA7d4lpO82UUq86NTD0wA0yWR_iI8RjQPMbdFEPlgqZ-pKKCUgHi0tFqZN1ESenrMxtYKbKlm-91s8R7RuE_mxrKbqB17Y/s1600/pytesseract.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr90lPwJQQKCDH5U5EmQyTnQh_UzHQg5GbnvkeFXUXuGjULwA7d4lpO82UUq86NTD0wA0yWR_iI8RjQPMbdFEPlgqZ-pKKCUgHi0tFqZN1ESenrMxtYKbKlm-91s8R7RuE_mxrKbqB17Y/s640/pytesseract.jpg" width="640" /></a></div>
<br />
<h2 class="heading1" style="background-color: white; border-bottom-color: rgb(207, 202, 202); border-bottom-style: dashed; border-width: 0px 0px 1px; color: #50317b; font-family: "roboto condensed", arial, sans-serif; font-size: 26px; letter-spacing: -0.5px; line-height: 34px; margin: 45px 0px 18px; opacity: 1; outline: 0px; padding: 0px 0px 4px; transition: all 0.24s ease-in-out 0s; vertical-align: baseline; visibility: visible;">
pytesseract 安裝教學</h2>
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">pip </span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">install </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">pytesseract</span></pre>
<br />
<h2 class="heading1" style="background-color: white; border-bottom-color: rgb(207, 202, 202); border-bottom-style: dashed; border-width: 0px 0px 1px; color: #50317b; font-family: "roboto condensed", arial, sans-serif; font-size: 26px; letter-spacing: -0.5px; line-height: 34px; margin: 45px 0px 18px; opacity: 1; outline: 0px; padding: 0px 0px 4px; transition: all 0.24s ease-in-out 0s; vertical-align: baseline; visibility: visible;">
pytesseract 函數庫</h2>
<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">https://github.com/UB-Mannheim/tesseract/wiki</span></pre>
<br />
<b><span style="font-size: large;">依據電腦系統規格下載適合的函數庫</span></b><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVbGie_nKrCq_Uq9UBnXF805auDXU3nSquXtwhMMtOw90oHHHvWoUgbOWXgp_XmBHh5dr-lzB-pmxXfbUTwDhSUeHXgPh9hl23Z05Ed8qwAjwUVnKtcdh1WdaV8u4W2ZQkXYYhxZfxjMpZ/s1600/pyseract.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="645" data-original-width="742" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVbGie_nKrCq_Uq9UBnXF805auDXU3nSquXtwhMMtOw90oHHHvWoUgbOWXgp_XmBHh5dr-lzB-pmxXfbUTwDhSUeHXgPh9hl23Z05Ed8qwAjwUVnKtcdh1WdaV8u4W2ZQkXYYhxZfxjMpZ/s1600/pyseract.png" /></a></div>
<div style="text-align: center;">
<b><span style="font-size: large;"><br /></span></b></div>
<div style="text-align: center;">
<b><span style="font-size: large;"><br /></span></b></div>
<b><span style="font-size: large;">環境變數設定 → 本機 → 內容 → 進階系統設定 → 環境變數 → 系統變數 → path → 添加路徑(以安裝位置為主) C:\Program Files\Tesseract-OCR</span></b><br />
<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"><span style="color: #6aa84f;"># 辨識教學範本</span><span style="color: magenta;">
import</span><span style="color: white;"> pytesseract
</span></span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">import </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">pyautogui
</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">import </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">cv2
pytesseract.pytesseract.tesseract_cmd = r</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'C:\Program Files\Tesseract-OCR\tesseract.exe'</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
config = </span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'--psm 8 --oem 3 -c tessedit_char_whitelist=0123456789'</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
pyautogui.screenshot</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">r</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'C:\Users\jojo\Desktop\1235.png'</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">,</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">region</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">=</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">82, 271, 39 ,16</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
img = cv2.imread</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">r</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">"C:\Users\jojo\Desktop\1235.png"</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
orc = pytesseract.image_to_string</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">img, </span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">config</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">=config</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #3d85c6; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">print</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">orc</span><span style="color: #ffd966;"><span style="font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> </span></span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"># 印出辨識的文字</span></pre>
<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"># config 參數
# 0 Orientation and script detection (OSD) only.
# 1 Automatic page segmentation with OSD.
# 2 Automatic page segmentation, but no OSD, or OCR.
# 3 Fully automatic page segmentation, but no OSD. (Default)
# 4 Assume a single column of text of variable sizes.
# 5 Assume a single uniform block of vertically aligned text.
# 6 Assume a single uniform block of text.
# 7 Treat the image as a single text line.
# 8 Treat the image as a single word.
# 9 Treat the image as a single word in a circle.
# 10 Treat the image as a single character.
# 11 Sparse text. Find as much text as possible in no particular order.
# 12 Sparse text with OSD.
# 13 Raw line. Treat the image as a single text line, bypassing hacks that are Tesseract-specific.</span></pre>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-51121521580026319262020-01-01T18:34:00.003-08:002020-01-02T19:02:26.529-08:00使用 pyppeteer 遇見 BrowserError: Failed to connect to browser port 解決辦法<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO_yYLwKxnjwsWQ-g4XtrrgM53xw5q5otabJl3FleYXUPha08kdxHpl7Pgm-w4f5mOCZHDz-ovQibeZijkulGgzDdCDaFkMs2spxIKmcHmbN9_WoFBB1_s-8p20vmW93wbF2hX95eaL8w/s1600/puppeteer.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1000" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO_yYLwKxnjwsWQ-g4XtrrgM53xw5q5otabJl3FleYXUPha08kdxHpl7Pgm-w4f5mOCZHDz-ovQibeZijkulGgzDdCDaFkMs2spxIKmcHmbN9_WoFBB1_s-8p20vmW93wbF2hX95eaL8w/s640/puppeteer.jpg" width="592" /></a></div>
<br />
<h2 class="heading1" style="background-color: white; border-bottom-color: rgb(207, 202, 202); border-bottom-style: dashed; border-width: 0px 0px 1px; color: #50317b; font-family: "roboto condensed", arial, sans-serif; font-size: 26px; letter-spacing: -0.5px; line-height: 34px; margin: 45px 0px 18px; opacity: 1; outline: 0px; padding: 0px 0px 4px; transition: all 0.24s ease-in-out 0s; vertical-align: baseline; visibility: visible;">
輸入以下指令,可以解決 Pyppeteer 所產生的錯誤訊息</h2>
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">sudo apt-get install gconf-service libasound2 libatk1.0-0 libc6
libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4
libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0
libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1
libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget</span></pre>
<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"># 此解法參考 pyppeteer 在 github 所發佈的解決辦法</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"># 參考連結 https://github.com/puppeteer/puppeteer/issues/2462</span></pre>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com1tag:blogger.com,1999:blog-8901394207076719638.post-17117577905602851802019-12-31T20:05:00.002-08:002019-12-31T20:05:52.160-08:00使用 BeautifulSoup 常見得錯誤訊息 object of type 'Response' has no len()<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"><span style="color: white;">object of type </span><span style="color: #f6b26b;">'Response'</span><span style="color: white;"> has no len()</span><span style="color: #6aa84f;">
# 上述的錯誤訊息是新手使用 BeautifulSoup 常遇見的錯誤
# 最主要的原因是忘了加 content 的方法
# 解決方法如下
</span><span style="color: magenta;">import </span><span style="color: white;">requests
headers = </span><span style="color: #ffd966;">{</span><span style="color: white;">
</span><span style="color: #f6b26b;">'content-type'</span><span style="color: white;">: </span><span style="color: #f6b26b;">'text/html; charset=UTF-8'</span><span style="color: white;">,
</span><span style="color: #f6b26b;">'user-agent'</span><span style="color: white;">: </span><span style="color: #f6b26b;">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36'</span><span style="color: white;">
</span><span style="color: #ffd966;">}</span><span style="color: white;">
url = </span><span style="color: #f6b26b;">'https://python-learnnotebook.blogspot.com/'</span><span style="color: white;">
response = requests.get</span><span style="color: #ffd966;">(</span><span style="color: #6fa8dc;">url</span><span style="color: white;">=url,</span><span style="color: #6fa8dc;">headers</span><span style="color: white;">=headers,</span><span style="color: #6fa8dc;">timeout</span><span style="color: white;">=15</span><span style="color: #ffd966;">)</span><span style="color: white;">
html = response.content </span><span style="color: #6aa84f;"># host return result use content method can slove your issue</span><span style="color: white;">
soup = BeautifulSoup</span><span style="color: #ffd966;">(</span><span style="color: white;">html, </span><span style="color: #f6b26b;">'html.parser'</span><span style="color: #ffd966;">)</span><span style="color: white;">
</span></span></pre>
<div>
<span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"><br /></span></div>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-84104217422654534842019-12-31T19:13:00.002-08:002020-04-08T21:47:43.266-07:00python 陳述句寫法<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCZgx6b9ZpFdpsfi1TdxgroKjcu7OHeZ53M6m3mi9_NOpqrbdIHa70hMu2fqGMUXZcyNGaYUOswSbiXYsB5NEw33AnHGDopGykyxrdDcsS7qLg0LVTvDjQ1COW1GiSDe2JHy6KUE8pA4k/s1600/python.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="335" data-original-width="670" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCZgx6b9ZpFdpsfi1TdxgroKjcu7OHeZ53M6m3mi9_NOpqrbdIHa70hMu2fqGMUXZcyNGaYUOswSbiXYsB5NEw33AnHGDopGykyxrdDcsS7qLg0LVTvDjQ1COW1GiSDe2JHy6KUE8pA4k/s1600/python.jpg" /></a></div>
<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">#</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> python3.5 以後支持這種陳述句寫法
# 可以在 args 內做 remark,告訴其他人該傳何種型態的參數
</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">def</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> test</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">a: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">int</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">, b: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">str </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">, c: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">str </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">= 5</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> -> </span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">"you remark"</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">:
</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">return</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> a, b, c
</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">def </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">test_1</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">a: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">int</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">, b: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">str </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">, c: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">str </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">= 5</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> -> </span><span style="color: lime; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">list</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">:
</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">return </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">a, b, c
</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">def </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">test_2</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">a: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">int</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">, b: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">str </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">, c: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">str </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">= 5</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> -> </span><span style="color: lime; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">dict</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">:
</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">return </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">a, b, c
</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">def </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">test_3</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">a: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">int</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">, b: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">str </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">, c: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">str </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">= 5</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> -> </span><span style="color: lime; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">tuple</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">:
</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">return </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">a, b, c
</span></pre>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-60195499670015673412019-12-31T19:01:00.000-08:002020-01-03T19:03:54.999-08:00如何使用 python 做自動化佈署 how to auto deploy python code<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4gQ5Y6B8YZbkOoPQ_QKsiA4iY3PJja1TnLxB_x9CDnHU4e-wm-jAT07DPBqwtQZtmJ2MZKOUosHNP74NDmUhsq1AhH_eCPa8dQiwokypn9wwExV3k0NjLD3l3NezbR7HN1w9iR_2BIyI/s1600/deploy.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4gQ5Y6B8YZbkOoPQ_QKsiA4iY3PJja1TnLxB_x9CDnHU4e-wm-jAT07DPBqwtQZtmJ2MZKOUosHNP74NDmUhsq1AhH_eCPa8dQiwokypn9wwExV3k0NjLD3l3NezbR7HN1w9iR_2BIyI/s640/deploy.jpg" width="640" /></a></div>
<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">from </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">fabric.api </span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">import </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">*</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# Automatically catch errors
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">env.warn_only = </span><span style="color: #3d85c6; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">True</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# Enable multi-process tasks
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">env.parallel = </span><span style="color: #3d85c6; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">True</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
env.hosts =</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> [</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'ubuntu@127.0.0.1'</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">,
</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'ubuntu@127.0.0.2'</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">]</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
env.passwords = </span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">{</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'ubuntu@127.0.0.1:22'</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">: </span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">"password_1"</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">,
</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'ubuntu@127.0.0.2:22'</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">: </span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">"password_1"</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">}</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">def </span><span style="color: #fff2cc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">test</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">()</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">:
sudo</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'mkdir /home/ubuntu/jojo'</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">def </span><span style="color: #fff2cc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">upload</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">()</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">:
</span><span style="color: #6aa84f;"><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">put</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'local host path'</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">,</span><span style="color: #f6b26b;"><span style="font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> </span><span style="font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'remote host path'</span></span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span></span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">def </span><span style="color: #fff2cc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">pip_commend</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">()</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">:
run</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">"pip install modlue name....."</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span></pre>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-43214491039558232832019-12-29T06:36:00.004-08:002019-12-29T06:37:31.065-08:00python IndexError: list index out of range 問題<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 1000em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"><b><span style="color: #6aa84f;">會發生這個錯誤的原因,主要是因為你索引超出了 list 的範圍而產生的錯誤
那具體該如何避免呢?
錯誤示範 :
</span><span style="color: white;">tes_ls = </span><span style="color: #ffd966;">[</span><span style="color: white;">0,1</span><span style="color: #ffd966;">]</span><span style="color: white;">
test_ls</span><span style="color: #ffd966;">[</span><span style="color: white;">3</span><span style="color: #ffd966;">]</span><span style="color: #6aa84f;">
解法一 :
可以先判斷 list 本身的長度,然後再取值
</span><span style="color: #f3f3f3;">
</span><span style="color: magenta;">if </span><span style="color: cyan;">len</span><span style="color: #ffd966;">(</span><span style="color: #f3f3f3;">tes_ls</span><span style="color: #ffd966;">)</span><span style="color: #f3f3f3;"> >= 4:
test_ls</span><span style="color: #ffd966;">[</span><span style="color: #f3f3f3;">3</span><span style="color: #ffd966;">]</span><span style="color: #f3f3f3;">
</span><span style="color: magenta;">else</span><span style="color: #f3f3f3;">:
</span><span style="color: #6fa8dc;">print</span><span style="color: #ffd966;">(</span><span style="color: #f6b26b;">"The list length is not enough"</span><span style="color: #ffd966;">)</span><span style="color: #6aa84f;">
解法二 :
</span><span style="color: magenta;">try</span><span style="color: white;">:
test_ls</span><span style="color: #ffd966;">[</span><span style="color: white;">3</span><span style="color: #ffd966;">]</span><span style="color: white;">
</span><span style="color: magenta;">except</span><span style="color: white;">:
</span><span style="color: #6fa8dc;">print</span><span style="color: #ffd966;">(</span><span style="color: #f6b26b;">"list index out of range"</span><span style="color: #ffd966;">)</span></b></span></pre>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com2tag:blogger.com,1999:blog-8901394207076719638.post-20088390756475476652019-12-29T06:10:00.001-08:002019-12-29T06:10:52.638-08:00該如何解決Pyppeteer的Target closed 錯誤問題<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 1000em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"><b>當在使用</b> </span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"><b>Pyppeteer 控制 browser 去執行 page.click() 方法的時候,會遇見奇怪的錯誤
</b></span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"><b>如下的錯誤訊息</b></span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">Protocol error Target.activateTarget: Target closed.</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span></pre>
<div>
<br /></div>
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 1000em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="font-family: consolas, monaco, andale mono, ubuntu mono, monospace; font-size: large;"><b><span style="color: #6aa84f;">將現有的 websockets 版本移除
</span><span style="color: white;">pip uninstall websockets</span></b></span></pre>
<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 1000em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="font-family: consolas, monaco, andale mono, ubuntu mono, monospace; font-size: large;"><b><span style="color: #6aa84f;">在降低版本安裝回去,就能解決 target close 問題</span><span style="color: white;">
pip install websockets==6.0</span></b></span></pre>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-9805850510284510752019-06-17T22:58:00.001-07:002019-06-18T02:08:24.074-07:00Linux Ubuntu 安裝 Anaconda 指令教學<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD4CIXGVZRYq3Zd34Hu-ZcbR1Yh5CubViT_7KEq6qCAj51-iONIlhxWMA7r2UtlxT8EM2V-nswKisvN58ko8RbukTk0eBxYQZ_LlSevrDd9jjlzaQWNq39dcMGwirGrf67Q5ZMGApcGqQ/s1600/Anaconda.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="168" data-original-width="300" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD4CIXGVZRYq3Zd34Hu-ZcbR1Yh5CubViT_7KEq6qCAj51-iONIlhxWMA7r2UtlxT8EM2V-nswKisvN58ko8RbukTk0eBxYQZ_LlSevrDd9jjlzaQWNq39dcMGwirGrf67Q5ZMGApcGqQ/s640/Anaconda.jpg" width="640" /></a></div>
<br />
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 1000em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">1.首先下載安裝 Anaconda sh 檔</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
wget </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">2. 安裝 Anaconda</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
echo </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'export PATH="~/anaconda3/bin:$PATH"' >> ~/.bashrc</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">3.添加環境變量</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
bash </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">Anaconda3-5.0.1-Linux-x86_64.sh</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
source </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">.bashrc</span></pre>
<br />王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-40673517053105849812019-05-27T23:50:00.002-07:002019-06-11T07:08:37.784-07:00BeautifulSoup 常用的網頁解析器<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgCxdwGLc4YvW1DywECUSOMEZdC75VUAesRdE14-HcHWJNCMrJP3sR8HFsR0uNhlZ-Kn4yGZ2-7-2XIoujmeOPADdCgSi329vnliZ04XrB39KKd5dOcG1FphMFRqyHOHFtu_ADVj_3y-4/s1600/beautifulsoup.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="658" data-original-width="862" height="488" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgCxdwGLc4YvW1DywECUSOMEZdC75VUAesRdE14-HcHWJNCMrJP3sR8HFsR0uNhlZ-Kn4yGZ2-7-2XIoujmeOPADdCgSi329vnliZ04XrB39KKd5dOcG1FphMFRqyHOHFtu_ADVj_3y-4/s640/beautifulsoup.jpeg" width="640" /></a></div>
<br />
<br />
<pre data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 100em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"># BeautifulSoup 常用的網頁解析器
</span><span style="font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"><span style="color: #f3f3f3;">BeautifulSoup</span><span style="color: #ffd966;">(</span><span style="color: #f3f3f3;">html</span></span><span style="color: #f3f3f3; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">,</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> </span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">"html.parser"</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">) # → 速度中等,容錯率強,python內建資料庫
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">BeautifulSoup</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">html,</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> </span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">"lxml"</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> # → 速度快,但須裝C語言套件
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">BeautifulSoup</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">html,</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> </span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">"xml"</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> # → 速度快,但須裝C語言套件
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">BeautifulSoup</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">html,</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> </span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">"html5lib"</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> # → 速度慢,容錯率最強,不須安裝額外套件
# 常見 error
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">BeautifulSoup: </span><span style="color: cyan; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">object </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">of </span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">type </span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'Response'</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> has no len()</span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
# 解決方法如下:
</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">res = requests.get</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">url</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">.content</span></pre>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com2tag:blogger.com,1999:blog-8901394207076719638.post-41478948765038128032019-05-23T07:48:00.001-07:002019-05-23T07:52:06.209-07:00pip install windows 一鍵安裝大量library方法<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDY17ZVFypFngBEehyphenhyphen03-1PzdDAIdCHL2KE5nh-f1VpezMDI8Vm4rqAk0jLln4fO0csuKdojfRoEFJKa1XDEdmwBTMjohR82z6Vjp-oi9ndmtcodREjCUIUoYsUvn_sZKLtvHbeXWEhxQ/s1600/PIP_logo-zwart_groot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="359" data-original-width="600" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDY17ZVFypFngBEehyphenhyphen03-1PzdDAIdCHL2KE5nh-f1VpezMDI8Vm4rqAk0jLln4fO0csuKdojfRoEFJKa1XDEdmwBTMjohR82z6Vjp-oi9ndmtcodREjCUIUoYsUvn_sZKLtvHbeXWEhxQ/s1600/PIP_logo-zwart_groot.png" /></a></div>
<br /></div>
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>獲取當前環境的所有套件,存成 Text 文字檔</b></span></div>
<div>
<b style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;">pip freeze > requirements.txt</b></div>
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span>
<br />
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>安裝 </b></span><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">requirements.txt 所有套件</span></b></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">pip install -r requirements.txt</span></b></div>
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>產生維護升級用的</b></span><b style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;">Text 文字檔</b></div>
<div>
<b style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;">pip freeze ></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> requirements-update.txt</span></b></div>
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>升級維護用的</b></span><b style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;">Text 文字檔</b></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">pip install -r requirements-to-freeze.txt --upgrade</span></b><br />
<br />
<b><span style="font-size: large;"><br /></span></b>
<b><span style="font-size: large;">使用pip 一次安裝多個 library</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">pip install pillow pymysql jieba </span></b>王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-49936522247262546652019-04-01T21:18:00.001-07:002019-04-15T00:57:54.311-07:00python 課程教學<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaV-4dLstdJppUuP3WqvmMsojpaLSHFjkrSiG6ZVw9-LqtnXhgPIdPdjURaAClDKutWePtqapuZ3GsZDeyMiA-WcKRvrpntkO-J-w3p3EX-RZUiCmRaydjYBN2hWaukqs6J0CWBFCKRP8/s1600/python.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="163" data-original-width="310" height="336" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaV-4dLstdJppUuP3WqvmMsojpaLSHFjkrSiG6ZVw9-LqtnXhgPIdPdjURaAClDKutWePtqapuZ3GsZDeyMiA-WcKRvrpntkO-J-w3p3EX-RZUiCmRaydjYBN2hWaukqs6J0CWBFCKRP8/s640/python.jpg" width="640" /></a></div>
<br />
<br />
<span style="font-size: large;"><b>本站寫了很多教學文章,為了方便大家在找文章的時候,可以快速的導覽到你想要的教學,故寫了這篇文章,方便大家學習</b></span><br />
<b><span style="font-size: large;"><br /></span></b>
<b><span style="font-size: large;">1.<a href="https://python-learnnotebook.blogspot.com/2018/10/python-for-loop.html">Python for 迴圈教學</a></span></b><br />
<b><span style="font-size: large;">2.<a href="https://python-learnnotebook.blogspot.com/2018/11/python-dictionary.html">Python dictionary 教學</a></span></b><br />
<b><span style="font-size: large;">3.<a href="https://python-learnnotebook.blogspot.com/2018/10/python-datetime-format.html">Python datetime format 教學</a></span></b><br />
<div>
<b><span style="font-size: large;">4.<a href="https://python-learnnotebook.blogspot.com/2018/11/python-multiprocessing-process-and-pool.html">Python 多進程 Multiprocessing Process and Pool 教學範例</a></span></b><br />
<b><span style="font-size: large;">5.<a href="https://python-learnnotebook.blogspot.com/2018/01/python-listappend.html">Python list.append 用法教學</a></span></b><br />
<b><span style="font-size: large;">6.<a href="https://python-learnnotebook.blogspot.com/2018/11/python-class.html">Python class 教學</a></span></b><br />
<b><span style="font-size: large;">7.<a href="https://python-learnnotebook.blogspot.com/2018/10/beautiful-soup-soup-beautifulsouphtml.html">Beautiful Soup 中文教學 html.parser 用法</a></span></b></div>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com2tag:blogger.com,1999:blog-8901394207076719638.post-56842047419301127042018-12-21T02:12:00.001-08:002019-07-01T18:48:32.485-07:00如何啟動 Firefox headless 無頭騎士模式<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0lay0iluDBH_HDHuMNRaj33OtERAyMvgt9H0XbBKcdbxeaWdYYX4BtvwI0kmkB_Jfez6IfQyhUqxam3q4OaATjDHPQ2XUJzKZ4HoiVjppIIhbzvKlBIMx6BhCZh2BBuOKWuxv23p1X3c/s1600/headless.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="759" data-original-width="900" height="538" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0lay0iluDBH_HDHuMNRaj33OtERAyMvgt9H0XbBKcdbxeaWdYYX4BtvwI0kmkB_Jfez6IfQyhUqxam3q4OaATjDHPQ2XUJzKZ4HoiVjppIIhbzvKlBIMx6BhCZh2BBuOKWuxv23p1X3c/s640/headless.jpg" width="640" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>之前有教過大家如何使用 <a href="https://python-learnnotebook.blogspot.com/2018/10/chrome-headless.html">Chrome headless</a> 來做網頁爬蟲</b></span><br />
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>,今天來聊聊如何用 </b></span><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Firefox headless 不開啟網頁來進行爬蟲工作 !!</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span></div>
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>好 ! 直接殺入主題</b></span></div>
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 8px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">1.首先導入我們要用的 lbrary</span></h2>
<div>
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 1000em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">from </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">selenium.webdriver.firefox.options</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> import Options
from </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">selenium </span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">import </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">webdriver</span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
from </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">bs4 </span><span style="color: magenta; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">import </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">BeautifulSoup</span></pre>
</div>
<div>
<!--代碼區塊-->
<!--代碼區塊-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 8px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">2.加入 headless function</span></h2>
</div>
<div>
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 1000em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">opts = Options</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">()</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
opts.set_headless</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">headless</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">=True</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
assert opts.headless</span></pre>
<!--代碼區塊-->
<!--代碼區塊-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 8px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">3.打開browser 執行自己的爬蟲程式</span></h2>
</div>
<div>
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 1000em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">driver = webdriver.Firefox</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">options</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">=opts,</span><span style="color: #6fa8dc; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">executable_path</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">=</span><span style="color: #f6b26b; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">'geckodriver.exe'</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)
driver.get</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">url</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
driver.implicitly_wait</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">(</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">30</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">)</span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"> </span><span style="color: #6aa84f; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;"># 隱性等待30,超過跳出error </span><span style="color: white; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">
driver.maximize_window</span><span style="color: #ffd966; font-family: "consolas" , "monaco" , "andale mono" , "ubuntu mono" , monospace; font-size: large;">()</span></pre>
<!--代碼區塊-->
<!--代碼區塊-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 8px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">4.關閉 browser</span></h2>
<div>
<pre class=" language-python" data-src-loaded="" data-src="prism.js" style="background: rgb(45, 45, 45); line-height: 1.5; margin-bottom: 0.5em; margin-top: 0.5em; max-height: 1000em; overflow-wrap: normal; overflow: auto; padding: 1em; word-break: normal;"><span style="font-family: consolas, monaco, andale mono, ubuntu mono, monospace; font-size: large;"><span style="color: white;">driver.close</span><span style="color: #ffd966;">()</span><span style="color: #6aa84f;"> # 關閉瀏覽器</span><span style="color: white;">
driver.quit</span><span style="color: #ffd966;">()</span><span style="color: white;"> </span><span style="color: #6aa84f;"># 退出程序</span><span style="color: white;"> </span></span></pre>
</div>
</div>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-10383570703195579212018-12-21T02:02:00.000-08:002018-12-21T02:02:16.433-08:00Cmder 常用快捷鍵<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg191lxCBXOkfHX6X-vCQcSp6wYLW6m_p-Vcf0AmdUHmjuw4T0z5gNEyNPfOWaBGl6485-cNd-YZIbuWiI-LRYEEBREQ7KE1sJYRtmu-aDWR3O5lTuFHthvIVnUrG19verqWfX3VTNY7pE/s1600/cmder+%25E5%25B8%25B8%25E7%2594%25A8%25E5%2591%25BD%25E4%25BB%25A4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg191lxCBXOkfHX6X-vCQcSp6wYLW6m_p-Vcf0AmdUHmjuw4T0z5gNEyNPfOWaBGl6485-cNd-YZIbuWiI-LRYEEBREQ7KE1sJYRtmu-aDWR3O5lTuFHthvIVnUrG19verqWfX3VTNY7pE/s640/cmder+%25E5%25B8%25B8%25E7%2594%25A8%25E5%2591%25BD%25E4%25BB%25A4.jpg" width="640" /></a></div>
<br />
<br />
<!--標題-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">Cmder常用快捷鍵</span></h2>
<!--標題-->
<b><br /><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Tab → 自動補全相似文件 or 路徑</span></b><br />
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />Ctrl+T → 建立新頁面,利用Ctrl+W關閉頁面</span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />Ctrl+Tab → 切換頁面</span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />Alt+F4 → 關閉所有頁面</span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />Alt+Shift+1 → 開啟cmd.exe </span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />Alt+Shift+2 </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">→ </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">開啟powershell.exe </span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />Alt+Shift+3 </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">→ </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">開啟powershell.exe (系統管理員權限) </span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />Ctrl+1 </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">→ </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">快速切換到第1個頁面</span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />Ctrl+n </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">→ </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">快速切換到第n個頁面( n值無上限) </span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />Alt + enter </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">→ </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">切換到全屏狀態</span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />Ctr+r </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">→</span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> 歷史命令搜索</span></b></div>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-68238083089459628922018-12-06T23:08:00.003-08:002018-12-07T00:22:56.599-08:00python for in 優雅乾淨的寫法<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUiIFEQE0ZNMsnvDEO4vBgD3DxEJ4k0WgNqfmstoxKosApFm9VmYXZMQkPcAB84I5Adg1sPMCQjNsKIJLp-17VV32mjeLUXl5OX3t1BqFPcc_YYijuTSFLhxFs1uJnhtmD8d0ePVeMrRg/s1600/python+for+in.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="418" data-original-width="784" height="341" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUiIFEQE0ZNMsnvDEO4vBgD3DxEJ4k0WgNqfmstoxKosApFm9VmYXZMQkPcAB84I5Adg1sPMCQjNsKIJLp-17VV32mjeLUXl5OX3t1BqFPcc_YYijuTSFLhxFs1uJnhtmD8d0ePVeMrRg/s640/python+for+in.png" width="640" /></a></div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>大部分書的中的寫法都是以這種方式來撰寫,這是比較標準的寫法,但是有沒有更乾淨更優有的寫法呢?</b></span><br />
<!--標題-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">範例一</span></h2>
<br />
<br />
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 200px; margin: 0px; padding-top: 8px; width: 600px;">a = ["jojo","mary","lulu","joe"]
b = []
for i in a:
b.append(i)
print(b)
</textarea>
<!--代碼區塊-->
<br />
<br />
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">其實還真的有更簡短的寫法 !!</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">大家可以看看範例二的寫法,可以縮短寫程式的長度,不用寫到落落長 。</span></b><br />
<!--標題-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">範例二</span></h2>
<br />
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 100px; margin: 0px; padding-top: 8px; width: 600px;">a = ["jojo","mary","lulu","joe"]
b = [i for i in a]
print(b)
</textarea>
<!--代碼區塊-->
<br />
<br />
<!--標題-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">更進階的用法</span></h2>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">如果今天需要造出Json的格式該怎麼做出來呢?這個時候可以利用 for in 加上 zip 漂亮造出你想要的dictionary格式</span></b><br />
<div>
<br /></div>
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 400px; margin: 0px; padding-top: 8px; width: 600px;">hg_list = []
league = ['美國大聯盟', '美國小聯盟']
team_name = ['波士頓紅襪','路易威爾蝙蝠']
time = ['11/12','10/22']
for league, team_name, time in zip(league, team_name, time):
hg_list.append({
"聯盟":league,
"隊伍名稱":team_name,
"比賽時間":time,
})
for i in hg_list:
print(i)
</textarea>
<!--代碼區塊--></div>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com1tag:blogger.com,1999:blog-8901394207076719638.post-79836289165760831622018-11-30T03:24:00.000-08:002019-01-19T22:10:36.132-08:00python class 教學及範例<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSZQyrI9qIiLUNK_oMT6w0XQG4HlgGp8sJJNKsoIcjxtmyikoUXsalknFsrqldkp5mIHIbe3lRbQZfsCPGsbQ8D5PU91gX6rZB_XE9b59p0t95JkiPUZ95iwGlrwiQAg9YG54dT7VufIc/s1600/python+class.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="383" data-original-width="685" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSZQyrI9qIiLUNK_oMT6w0XQG4HlgGp8sJJNKsoIcjxtmyikoUXsalknFsrqldkp5mIHIbe3lRbQZfsCPGsbQ8D5PU91gX6rZB_XE9b59p0t95JkiPUZ95iwGlrwiQAg9YG54dT7VufIc/s1600/python+class.png" /></a></div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>python 其實本身就是一種物件導向,可以說萬物皆物件的概念,但通常會在甚麼情況下要用的 class 這個語法呢?</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>其實當def 要定義的 function 數量過多的時候,可以透過class 再做更細部的分類,讓程式設計上有更多靈活調度的空間</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>當然 ! 如果說不想使用class 語法來寫自己的code其實也並不影響撰寫出來的程式運作,只是提供了一種寫法給程式設計者來去coding自己的程式</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>大家可以透過以下的範例來延伸出自己想要的程式寫法。</b></span><br />
<br />
<!--標題-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">範例一</span></h2>
<br />
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 240px; margin: 0px; padding-top: 8px; width: 600px;">class jojo():
age = "27"
def talk(self):
return "hellow"
j = jojo() # 宣告成新物件
print(jojo.age)
print(j.talk())
</textarea>
<!--代碼區塊-->
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-JKKK90_PqaWvllWJYu4VUb8KvxFjpCouD9eKXRIhw9KraqtuJO_ZTphSWa8us0Se6Pn_Ev7Yfa1z1vJkj54YM-Et_1b4weA0ysmb_8WA6urI1vt8qdrkB8sFJvUP93fPgZ8PJ-S2tNI/s1600/python+class.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="231" data-original-width="701" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-JKKK90_PqaWvllWJYu4VUb8KvxFjpCouD9eKXRIhw9KraqtuJO_ZTphSWa8us0Se6Pn_Ev7Yfa1z1vJkj54YM-Et_1b4weA0ysmb_8WA6urI1vt8qdrkB8sFJvUP93fPgZ8PJ-S2tNI/s1600/python+class.png" /></a></div>
<br />
<!--標題-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">範例二</span></h2>
<!--標題-->
<br />
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 290px; margin: 0px; padding-top: 8px; width: 600px;">class jojo():
def __init__(self,age):
self.age = age
def talk(self,say):
return say
j = jojo("27")
print(j.age)
print(j.talk("hellow"))
</textarea>
<!--代碼區塊-->
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ2oQJ3cNgi1U-8ehcpmRw2EUlySGfN15TebMXMDF5S96mx_AcEtjjCi2X9EdoPXM8PZRqGuYUS-1MIxb4TOdJV5y5WO-96roAkXFXmncPijQ1ZJlgziLHMczHfp73wgEUEL7qIt3oLOY/s1600/python+class+age.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="235" data-original-width="650" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ2oQJ3cNgi1U-8ehcpmRw2EUlySGfN15TebMXMDF5S96mx_AcEtjjCi2X9EdoPXM8PZRqGuYUS-1MIxb4TOdJV5y5WO-96roAkXFXmncPijQ1ZJlgziLHMczHfp73wgEUEL7qIt3oLOY/s1600/python+class+age.png" /></a></div>
<br /><br /><b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">補充範例資料:</span></b><br /><br /><div class="separator" style="clear: both;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4xfTKc7a5VefjCT5JSGRN-9Mqwq2uEsaTCgMnIvRsc7rHQkh3W2EiaMvjrJHWcdDzolN1jO30GnEzQ5ajxg7-312P3SnvJIvFg9IMLPq9Z8bgNSdfH4i8ljOYPaeN6lWCmdY01SRyL6E/s1600/python+class.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="400" data-original-width="607" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4xfTKc7a5VefjCT5JSGRN-9Mqwq2uEsaTCgMnIvRsc7rHQkh3W2EiaMvjrJHWcdDzolN1jO30GnEzQ5ajxg7-312P3SnvJIvFg9IMLPq9Z8bgNSdfH4i8ljOYPaeN6lWCmdY01SRyL6E/s1600/python+class.png" /></a></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">這兩種寫法的結果都一樣,差異點在於程式靈活度的問題,一個是依存取的變數調整輸出的結果,而另一種是比較死板的寫法。</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<br />
<blockquote class="tr_bq">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">PS : 針對 def __init__(self,age) 此段說明一下,這是程式宣告初始化的起手式。</span></b></blockquote>
<br />
<br />王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-28248594317530029332018-11-19T22:01:00.000-08:002018-12-22T19:17:58.765-08:00python dictionary 常用指令教學<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghnBgqu3tZDVjP6seMucuDpa6wBbKjthstKtZ1G260OYA2OZ2s0zr_6iaJj7zuO5utvhgHIdiG48_RzxgxKwSo7NkV-8rwrnLcP0zEFEeTvHXT8a2zOgUk7ZqJDZnAtX3sduXBtwIEgZM/s1600/dict.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1080" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghnBgqu3tZDVjP6seMucuDpa6wBbKjthstKtZ1G260OYA2OZ2s0zr_6iaJj7zuO5utvhgHIdiG48_RzxgxKwSo7NkV-8rwrnLcP0zEFEeTvHXT8a2zOgUk7ZqJDZnAtX3sduXBtwIEgZM/s640/dict.jpg" width="640" /></a></div>
<br />
<br />
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">dict.values()</span></h2>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">如果要確認 dictionary 到底還有哪些 value 的時候,可以使用此function 來做 check</span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">dict = { <span style="color: blue;">1</span> : <span style="color: blue;">2</span>,<span style="color: #e06666;"> 'a'</span> : <span style="color: #e06666;">'b'</span>, <span style="color: #e06666;">'hello'</span> :<span style="color: #e06666;"> 'world'</span> } </span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="background-color: white; border: none; box-sizing: border-box; margin: 0px; outline: 0px; overflow-wrap: break-word; padding: 0px;"><span style="font-size: large;"><b><span style="color: #cc0000;">輸出結果</span></b></span></span><span style="font-size: large;"><b>
['b', <span style="color: blue;">2</span>, 'world']</b></span></span><br />
<br />
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">dict.keys()</span></h2>
</div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">可用keys() function 來去檢查所有的key,不需要把全部的結果都印出來</span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">dict = { </span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="color: blue;">1</span> : <span style="color: blue;">2</span>,<span style="color: #e06666;"> 'a'</span> : <span style="color: #e06666;">'b'</span>, <span style="color: #e06666;">'hello'</span> :<span style="color: #e06666;"> 'world'</span></span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> } </span></b><br />
<b style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: x-large;"><span style="color: #cc0000;"><br /></span></b>
<b style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: x-large;"><span style="color: #cc0000;">輸出結果</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">[<span style="color: #e06666;">'a'</span>, <span style="color: blue;">1</span>, <span style="color: #e06666;">'hello'</span>]</span></b><br />
<br />
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">dict.items()</span></h2>
</div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">items()會返回一整個 list,並且是組一組的 dictionary 所組成。</span></b><br />
<b style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: x-large;"><span style="color: #cc0000;">輸出結果</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">[(<span style="color: #e06666;">'a'</span>, <span style="color: #e06666;">'b'</span>), (<span style="color: blue;">1</span>, <span style="color: blue;">2</span>), (<span style="color: #e06666;">'hello'</span>, <span style="color: #e06666;">'world'</span>)]</span></b><br />
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">如果有需要寫大量更換帳號、密碼程式需求,剛好可以使用這種方法來解決問題</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>例如:</b></span><br />
<br />
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 170px; margin: 0px; padding-top: 8px; width: 800px;">acc_pas = {"acc_1":"pasd_1","acc_2":"pasd_2","acc_3":"pasd_3","acc_4":"pasd_4"}
a = acc_pas.items()
for acc,pas in a:
print("帳號-->",acc)
print("密碼-->",pas)
</textarea>
<!--代碼區塊-->
<br />
<br />
<b style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: x-large;"><span style="color: #cc0000;">輸出結果</span></b><br />
<b style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: x-large;"><span style="color: #cc0000;"><br /></span></b>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4TWUeXsqD6zL9i9OUvvPwaI-JHvIaYJ0iJ5V-kJ0c3DOOlZCL6BdEtFruwj3I4IFlyPq1ATBYi5OVcigRbBjfjFUfKWykqLt83uZ1dq_BQut__osYwcThS15eMqQPwvxE_i2Km7Zyyjc/s1600/dictionary.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="328" data-original-width="1251" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4TWUeXsqD6zL9i9OUvvPwaI-JHvIaYJ0iJ5V-kJ0c3DOOlZCL6BdEtFruwj3I4IFlyPq1ATBYi5OVcigRbBjfjFUfKWykqLt83uZ1dq_BQut__osYwcThS15eMqQPwvxE_i2Km7Zyyjc/s1600/dictionary.png" /></a></div>
<b style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: x-large;"><span style="color: #cc0000;"><br /></span></b>
<b style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: x-large;"><span style="color: #cc0000;"></span></b><br />
<div>
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">建立 dictonary 方法很多,而以下兩種方法都可以達到我們想要的結果</span></b></div>
<div>
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><br /></span></b></div>
<b><span style="font-family: Arial, Helvetica, sans-serif; font-size: large;">languages = {<br /> 'name': 'python',<br /> 'version': '3.5'<br />}<br /><br />dict([('name', 'python'), ('version', '3.5')])</span></b></div>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-41434709211017497662018-11-14T19:23:00.001-08:002018-11-14T19:29:27.322-08:00git 建立分支教學 building branch teaching<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFshzU0cozgGCO4wB9vqx6eLApHtXHKC8uTLbV38HmigPwJ1zw8Z7Irsj4Ep7oNJMSSPn37709uBpJgqa4mOM5Bw31p_foFIRZpA3GtAzcKvHm-ByYzU2PcsPfR_Er2YI4mmlZGsIfS7A/s1600/git+building+branch.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="400" data-original-width="801" height="319" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFshzU0cozgGCO4wB9vqx6eLApHtXHKC8uTLbV38HmigPwJ1zw8Z7Irsj4Ep7oNJMSSPn37709uBpJgqa4mOM5Bw31p_foFIRZpA3GtAzcKvHm-ByYzU2PcsPfR_Er2YI4mmlZGsIfS7A/s640/git+building+branch.png" width="640" /></a></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">要如何開始建立自己的git 分支呢? 我自己剛開始自己建立分支的時候也是研究半天,我想很多剛開始git 的朋友應該也是很困擾吧 ! </span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">所以幫大家整理出一步驟,只要一步一步照著做就可以建立起自己的第一支 git 分支</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<br />
<blockquote class="tr_bq">
<b style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;">後續也會錄製影片教如何快速建立自己的git branch !</b></blockquote>
<br /></div>
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">1.首先將 git 上的原始資料 clone 下來</span></h2>
<!--標題區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">git clone git@git.sp168.cc:<帳號/檔名>.git
</span></b><br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">2.移動到下載下來的資料夾內 = 移動到本地的Repository</span></h2>
<!--標題區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">cd 資料夾位置
</span></b><br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">3.建立分支</span></h2>
<!--標題區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">git branch <分支名稱>
</span></b><br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">4.切換分支</span></h2>
<!--標題區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">git checkout <切換分支>
</span></b><br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">5.刪除分支</span></h2>
<!--標題區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>git branch -D <分支名稱>
</b></span><br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">6.加入要上傳的檔案</span></h2>
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">git add . → 加入所有更動或新增檔案</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">or</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">git add <檔案名稱>
</span></b><br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">7.檢查上傳狀態</span></h2>
<!--標題區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>git status
</b></span><br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">8. 提交檔案並附加" 註解 "</span></h2>
<!--標題區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>git commit -m "註解說明"
</b></span><br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">9.將資料推上 git </span></h2>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">git push origin <分支名稱></span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
</div>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-82823328235122250212018-11-07T18:35:00.003-08:002019-03-30T07:26:51.735-07:00python thread 多線程範例教學<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe2ODBkAEqT0R5dbTjgoczOXgjadEbWv_fytTjcgbRczGoOH3lzwLPdagZFN7b7pISuyETkChyphenhyphenofHurEvBBOCR7gBBcUNhd7H4Qhzd7bI1lcSwRkHs1Pi86b8JEwddr3dZKubMl8E9r8E/s1600/threading.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe2ODBkAEqT0R5dbTjgoczOXgjadEbWv_fytTjcgbRczGoOH3lzwLPdagZFN7b7pISuyETkChyphenhyphenofHurEvBBOCR7gBBcUNhd7H4Qhzd7bI1lcSwRkHs1Pi86b8JEwddr3dZKubMl8E9r8E/s640/threading.jpg" width="640" /></a></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">在執行爬蟲任務時,需要有更高效率的程式運行速度,可以透過多線程執行多工程序,達到縮短程式的運行時間</span></b>
<!--標題區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">說明</span></h2>
<div>
<b><span style="font-size: large;"><span style="color: blue;">優點</span>:多線程應用在高頻的 I/O 任務上</span></b><br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><span style="color: blue;"> 缺點</span>:原理是透過輪流爭取CPU工作間隔時間,達到多工效果,但是其中一個子線程掛掉會導致整支程式因此癱瘓</b></span>
<br />
<div>
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">導入多進程library</span></h2>
<!--標題區塊-->
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 65px; margin: 0px; padding-top: 8px; width: 600px;">from threading import Thread
import time
</textarea>
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">定義好要執行的程式區塊</span></h2>
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 180px; margin: 0px; padding-top: 8px; width: 600px;">def timer(name,delay,times):
print("計時器: "+ name + "開始")
while times > 0:
time.sleep(delay)
print(name + ": " + str(time.ctime(time.time())))
times -= 1
print("計時器: " + name + "完成")
</textarea>
<!--代碼區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">執行多線程</span></h2>
<!--標題區塊-->
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 275px; margin: 0px; padding-top: 8px; width: 600px;">def Main():
t1 = Thread(target=timer,args=("程式1",1,5))
t2 = Thread(target=timer,args=("程式2",2,5))
#程式開始
t1.start()
t2.start()
print("\n程式開始")
#程式結束
t1.join() # join() 等待程式自然結束或拋出Error
t2.join()
print("\n程式結束")
</textarea>
<!--代碼區塊-->
<br />
<br /></div>
</div>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-65686524155792260252018-11-07T17:37:00.000-08:002018-12-07T09:30:19.396-08:00Python 多進程 Multiprocessing Process and Pool 教學範例<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdQHjLkLXaw2wppxoh2UncoZaQU57vd4mSVwGp0ouQiwN2A8bcGDLAZONZcZOJ-h7OKJ58PHaIWJiu0Qoad5G71NyypeixLjgTHNwI_Sd0QHZQzIGEfM_E01LTiX_VibRF9rrCKNX9oAE/s1600/images.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="145" data-original-width="348" height="266" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdQHjLkLXaw2wppxoh2UncoZaQU57vd4mSVwGp0ouQiwN2A8bcGDLAZONZcZOJ-h7OKJ58PHaIWJiu0Qoad5G71NyypeixLjgTHNwI_Sd0QHZQzIGEfM_E01LTiX_VibRF9rrCKNX9oAE/s640/images.jpg" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">多進程善用電腦多核心的特性,多工並行的方式提升程式運行速度。</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">多進程與多線程的差異點在於開放的資源多寡,線程主要是用有限的資源達到最高效率,多進程則是開放多個資源達到最高效率。</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>若以穩定性來說的話,比較推薦使用多進程,因為多線程會因為其中一個子線程掛掉而導致整個程式癱瘓,但多進程不會因為其中一個進程掛掉而影響到其他子近程的運作</b></span><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">舉例來說,有多個工作桌,每位工人在各自的工作桌上工作,相對地所需CPU資源也較大</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>下圖有比較的差異</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXzdWfR3g4FVoyAbrG8pz0FvXGpb53iGrDvbwES62FatBJ1XA0UO5hfB7HugLdwWctNVC5k7CUWmXHJV27A8Kwd5qAxUZBaoyMmdad5_P6FslW35E2WToovDSfAGABGu8JzcmXxyY9T_c/s1600/%25E5%25A4%259A%25E9%2580%25B2%25E7%25A8%258B%25E8%2588%2587%25E5%25A4%259A%25E7%25B7%259A%25E7%25A8%258B%25E7%259A%2584%25E5%25B7%25AE%25E7%2595%25B0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="436" data-original-width="699" height="399" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXzdWfR3g4FVoyAbrG8pz0FvXGpb53iGrDvbwES62FatBJ1XA0UO5hfB7HugLdwWctNVC5k7CUWmXHJV27A8Kwd5qAxUZBaoyMmdad5_P6FslW35E2WToovDSfAGABGu8JzcmXxyY9T_c/s640/%25E5%25A4%259A%25E9%2580%25B2%25E7%25A8%258B%25E8%2588%2587%25E5%25A4%259A%25E7%25B7%259A%25E7%25A8%258B%25E7%259A%2584%25E5%25B7%25AE%25E7%2595%25B0.png" width="640" /></a></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">導入多進程library</span></h2>
<!--標題區塊-->
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 54px; margin: 0px; padding-top: 8px; width: 600px;">import multiprocessing as mp
</textarea>
<!--標題區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">定義子進程的function</span></h2>
<!--標題區塊-->
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 170px; margin: 0px; padding-top: 8px; width: 600px;">def claw(website):
print('hello')
def claw_a(website_a):
print('hello world')
</textarea>
<!--代碼區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">執行多進程</span></h2>
<!--標題區塊-->
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 280px; margin: 0px; padding-top: 8px; width: 600px;">if __name__ == '__main__': #必須放這段代碼,不然會Error
ap = mp.Process(target=claw, args=('website',))
jk = mp.Process(target=claw_a, args=('website_a',))
# 開始加速執行
ap.start()
jk.start()
# 結束多進程
ap.join()
jk.join()
</textarea><br />
<br />
<br />
<img alt="⚠" class="emoji" draggable="false" src="https://twemoji.maxcdn.com/2/72x72/26a0.png" style="border-style: none; box-sizing: inherit; color: grey; font-size: 30px; height: 1em; margin: 0px 0.05em 0px 0.1em; max-width: 100%; vertical-align: -0.1em; width: 1em;" /> <span style="background-color: white; color: #0b5394; font-family: "microsoft yahei"; font-size: 24px; font-weight: 700; letter-spacing: 1.4px;">Pool 進程池的用法</span><br />
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">導入需要的library</span></h2>
<!--標題區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 88px; margin: 0px; padding-top: 8px; width: 603px;">import time
from multiprocessing import Pool
</textarea><br />
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">定義子進程function</span></h2>
<!--標題區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 90px; margin: 0px; padding-top: 8px; width: 600px;">def run(fn) :
time.sleep(2)
print(fn)
</textarea>
<!--代碼區塊-->
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">執行多進程pool</span></h2>
<!--標題區塊-->
<br />
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 260px; margin: 0px; padding-top: 8px; width: 600px;">if __name__ == "__main__" :
startTime = time.time()
testFL = [1,2,3,4,5] # run function 的參數
pool = Pool() # Pool() 不放參數則默認使用電腦核的數量
pool.map(run,testFL)
pool.close()
pool.join()
endTime = time.time()
print("time :", endTime - startTime)
</textarea>
<!--代碼區塊-->
<br />
<br />
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">使用多進程Pool爬取蘋果熱門新聞</span></h2>
<!--標題區塊-->
<br />
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 1700px; margin: 0px; padding-top: 8px; width: 800px;">from bs4 import BeautifulSoup
import requests as res #導入requests library
import re
import time
from multiprocessing import Pool
import multiprocessing as mp
print('蘋果今日焦點')
def clawer(url):
headers = {'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'authority': 'tw.appledaily.com',
'accept':'text/html,application/xhtml+xml,application/xml;'
'q=0.9,image/webp,image/apng,*/*;q=0.8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
'(KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36'
}
s = res.session() #存取cookies
resp = s.get(url,headers=headers).text
soup = BeautifulSoup(resp, 'html5lib')
############### 清理標題 ############
new_title = []
titles = soup.find_all('div',{'class':"abdominis rlby clearmen"})
for s in titles:
s = s.find_all("h1")
for i in s:
i = i.text
new_title.append(i)
title = new_title[1:]
############### 清理連結 ############
for q in titles:
q = q.find_all(href=re.compile("^.*realtime\/\d{8}\/\d{7}\/$"))
hrefs = q
link=[]
for d in hrefs:
href = d.get('href')
link.append(href)
############### 建立 Json format ############
article = []
for title,link in zip(title,link):
article.append({
"標題":title,
"連結":link,
})
for i in article:
print(i)
if __name__ == "__main__" :
t1 = time.time()
urls=[]
for i in range(1,30):
v = str(i)
url = 'https://tw.appledaily.com/new/realtime/'+v
urls.append(url)
pool = Pool() # Pool() 不放參數則默認使用電腦核的數量
pool.map(clawer,urls)
pool.close()
pool.join()
print('Total time: %.1f s' % (time.time()-t1))
</textarea>
<!--代碼區塊-->王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com2tag:blogger.com,1999:blog-8901394207076719638.post-68295991000370303262018-11-01T02:19:00.000-07:002018-11-01T02:19:15.111-07:00如何避免爬蟲頻繁 requests server 導致被封鎖 IP<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrzGmHSej31cJ1EOyMf472IGU-jzvC_GsWZOeaHYUSJWnD_rLJe5_3oqSI1VQeDuHcFHkMO4rX6ddWjHiQ_Es47tdo8CAWBqFdqHj8cIrBKgPMytscYxT5wUeS2wUrFjqXtnssNXrFc-k/s1600/photo.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="900" data-original-width="1350" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrzGmHSej31cJ1EOyMf472IGU-jzvC_GsWZOeaHYUSJWnD_rLJe5_3oqSI1VQeDuHcFHkMO4rX6ddWjHiQ_Es47tdo8CAWBqFdqHj8cIrBKgPMytscYxT5wUeS2wUrFjqXtnssNXrFc-k/s640/photo.jpg" width="640" /></a></div>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b><br /></b></span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"><b>在爬取網頁的時候會頻繁requests網站提供數據,但這樣高頻的向主機端不斷提出請求是會被主機端網管人員針對性封鎖IP,這時候因應的辦法就是更換IP,避免爬行網站時被封鎖IP,可以參考以下的做法</b></span><br />
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">導入需要使用模塊</span></h2>
<!--標題區塊-->
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 65px; margin: 0px; padding-top: 8px; width: 600px;">import requests
from requests_toolbelt.adapters import source
</textarea><br />
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">程式寫法</span></h2>
<!--標題區塊-->
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 180px; margin: 0px; padding-top: 8px; width: 700px;">s = requests.Session() #使用會話方法儲存cookies
ip = 'xxx.xxx.xxx.xxx'
new_source = source.SourceAddressAdapter(ip) #調用搭配器的方法
#IP安裝在不同的通訊協定上,會自動調配適合的協定上面再做get or post的動作
s.mount('http://', new_source)
s.mount('https://', new_source)
</textarea>
<br />
<br />
<br />王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-14420139411386113552018-10-31T22:03:00.001-07:002018-12-21T02:35:25.931-08:00requests post example 範例<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKkMXT-FH1XmYBZJF1GlDzGw5RB9tJB6KPci6QhYfuaAVW77DblZG_f_LRLhL5yDAvEAwM2QeHunAz7BmHU3ZoEskwYi-Y415QtM8yXC2DsN8ziqxGsBgwqutuA83qfQqRqA83Qgi5zTY/s1600/photo-1539447322629-4100721554cd.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="900" data-original-width="1350" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKkMXT-FH1XmYBZJF1GlDzGw5RB9tJB6KPci6QhYfuaAVW77DblZG_f_LRLhL5yDAvEAwM2QeHunAz7BmHU3ZoEskwYi-Y415QtM8yXC2DsN8ziqxGsBgwqutuA83qfQqRqA83Qgi5zTY/s640/photo-1539447322629-4100721554cd.jpg" width="640" /></a></div>
<br /></div>
<div>
<b><span style="font-size: large;">
</span></b></div>
<div>
<b><span style="font-size: large;"></span></b> <a href="https://unsplash.com/public-domain-images">圖片來源</a><br />
<br />
<div style="display: inline !important;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>當我們在使用 request psot 的方式來傳遞資料時,設定參數有時會搞混data vaule到底是該放string還是json的格式,使用的時機整理如下</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span></div>
</div>
<div>
<blockquote class="tr_bq">
<b style="font-size: x-large;">打開Chrome 開發者工具可以找到 Request Header </b></blockquote>
</div>
<div>
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">而兩者本身的差異如下所示</span></h2>
<!--標題區塊-->
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>content-Type 為 json格式時,data就要轉成jason格式</b></span><br />
<span style="font-size: large;"><b style="font-family: Arial, Helvetica, sans-serif; font-size: medium;"><span style="font-size: large;">response</span></b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small;"> </span><b style="font-family: Arial, Helvetica, sans-serif; font-size: medium;"><span style="font-size: large;">= </span></b><b style="font-family: Arial, Helvetica, sans-serif; font-size: medium;"><span style="font-size: large;">s.post</span></b><b style="font-family: Arial, Helvetica, sans-serif; font-size: medium;"><span style="font-size: large;">( url,</span></b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small;"> </span></span><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>data</b></span><span style="font-size: large;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>=json.dumps(data))</b></span></span><br />
<span style="font-size: large;"><b><br /></b></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifFRNBGBKwQxs2Se5yKe9QVg8cYm7hh79usEscG5GVE-hJN-SVbb3b5llzbt9bZlYqjIFGVS_8cetqCB0XqZdeRbGBVoke3DfkWm9E9YH67C8s7RdP3gW-Wj_yBJMLNiODuod6H08cLWs/s1600/content+type.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="158" data-original-width="766" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifFRNBGBKwQxs2Se5yKe9QVg8cYm7hh79usEscG5GVE-hJN-SVbb3b5llzbt9bZlYqjIFGVS_8cetqCB0XqZdeRbGBVoke3DfkWm9E9YH67C8s7RdP3gW-Wj_yBJMLNiODuod6H08cLWs/s1600/content+type.png" /></a></div>
<span style="font-size: large;"><b><br /></b></span>
<span style="font-size: large;"><b style="font-family: arial, helvetica, sans-serif;">content-Type 為 xxx-form-urlencoded 時,data就放入string格式就可以了</b></span><br />
<span style="font-size: large;"><b style="font-family: arial, helvetica, sans-serif;"><br /></b></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhve-bJLT_8d9cJZ8RYpShdj0mzS_Z30Sch_jp-hOEnS-cJWJTucSay56v71TEfEUgMiA_iLfXnQTWtOuN6DHGhhGhcZk9Au5ObNW_vJiURcgeP11DCweN3wYsVTchcVmYhXMOx3sERo3o/s1600/content+type2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="178" data-original-width="509" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhve-bJLT_8d9cJZ8RYpShdj0mzS_Z30Sch_jp-hOEnS-cJWJTucSay56v71TEfEUgMiA_iLfXnQTWtOuN6DHGhhGhcZk9Au5ObNW_vJiURcgeP11DCweN3wYsVTchcVmYhXMOx3sERo3o/s1600/content+type2.png" /></a></div>
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";"> header 要如何寫?</span></h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYtK08WtPImAt4l1mydfoNRL_3HwaS1aenN11xTHM_dHQqSGDpv_6ug6o99lyDpihB7ef4UqvUD_qBQkJbo2bnzq6iCTTpwj0mm0di0omSUmxDeki6VTHXUB_KfSu2HMSDbW9zruIsnB4/s1600/header.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="350" data-original-width="1149" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYtK08WtPImAt4l1mydfoNRL_3HwaS1aenN11xTHM_dHQqSGDpv_6ug6o99lyDpihB7ef4UqvUD_qBQkJbo2bnzq6iCTTpwj0mm0di0omSUmxDeki6VTHXUB_KfSu2HMSDbW9zruIsnB4/s1600/header.png" /></a></div>
<b style="font-size: x-large;"><br /></b>
<b style="font-size: x-large;"><span style="font-family: "arial" , "helvetica" , sans-serif;">格式大概的寫法就跟python dictionary很像</span></b><br />
<b style="font-size: x-large;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></b>
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 300px; margin: 0px; padding-top: 8px; width: 800px;">headers = {
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Connection': 'keep-alive',
'Content-Length': '47',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X)'
'AppleWebKit/604.1.38 (KHTML, like Gecko)'
'Version/11.0 Mobile/15A372 Safari/604.1'
}
</textarea>
<!--代碼區塊-->
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">或者可以使用以下指令來判斷回傳的資料格式</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">response.json()</span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">看是否有噴出<span style="color: #cc0000;"> </span><span class="pre" style="hyphens: none;"><span style="color: #cc0000;">ValueError: No JSON object could be decoded</span><span style="font-family: "consolas" , "menlo" , "deja vu sans mono" , "bitstream vera sans mono" , monospace;"><span style="color: #cc0000;"> </span><span style="color: #222222;">這段錯誤</span></span></span></span></b></div>
<div>
<span class="pre" style="hyphens: none;"><span style="font-family: "consolas" , "menlo" , "deja vu sans mono" , "bitstream vera sans mono" , monospace;"><span style="color: #222222; font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>如果沒有也並不代表一定響應成功,因為有可以裡面藏有類似的 json 格式</b></span></span></span></div>
<div>
<span class="pre" style="hyphens: none;"><span style="font-family: "consolas" , "menlo" , "deja vu sans mono" , "bitstream vera sans mono" , monospace;"><span style="color: #222222; font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span></span></span></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">判斷是否回傳正常的響應→</span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">response.raise_for_status() </span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>檢查網站是否正常運作</b><b> → </b></span><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">response</span></b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>.status_code == requests.codes.ok </b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br /></b></span><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>查看 </b></span><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Content-Type(json or string) 格式→</span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">response</span></b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>.headers['Content-Type']</b></span></div>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0tag:blogger.com,1999:blog-8901394207076719638.post-26330337645207420412018-10-28T20:30:00.000-07:002018-10-30T23:27:40.528-07:00正規表達法 python regular expression 教學及用法<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5jq_6L-8blqv51jKYCFGZ_76BbL4R7sIve1xaj4nPXprcgud1W4CNEpOVgmrBODUSuWPMOvakjtvwk9lf3h5UPjyPlOCVWmD4cXq4lJb9V-tDBwrdZx691zOnTUSVe4ITpY04x2nCg_Q/s1600/regular+expression.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="902" data-original-width="1347" height="428" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5jq_6L-8blqv51jKYCFGZ_76BbL4R7sIve1xaj4nPXprcgud1W4CNEpOVgmrBODUSuWPMOvakjtvwk9lf3h5UPjyPlOCVWmD4cXq4lJb9V-tDBwrdZx691zOnTUSVe4ITpY04x2nCg_Q/s640/regular+expression.jpg" width="640" /></a></div>
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">很多剛學python的新手應該不是很懂正規表達法正確的用法,我幫大家整理出一些常用的function,大家可以參考以下的程式範例</span></b><br />
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">
<span style="font-family: "microsoft yahei";">match 用法</span></span></h2>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<!--標題區塊--><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">
找出符合的字串,如果要找完全符合的字串可以多加 "$",就會變成 → 'abc$'</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">要執行以下程式請先import re,不然無法執行</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 80px; margin: 0px; padding-top: 8px; width: 600px;">a = re.match('abc','abcd').group()
print(a)
</textarea><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">輸出結果</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHj-huxkE_y58KPcjhXwfDiwLEba6rMihJIq_CQNnlHNbbv_AdzJkl7ExF5n9Th870bkE7zph1TJRK4mxbK6JFVlnrL27VHSesZaQ6meprqLtP7Q7Ol0SAP3MLieJFdMhSAl1x5x2VRF8/s1600/regular+expression.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="104" data-original-width="1007" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHj-huxkE_y58KPcjhXwfDiwLEba6rMihJIq_CQNnlHNbbv_AdzJkl7ExF5n9Th870bkE7zph1TJRK4mxbK6JFVlnrL27VHSesZaQ6meprqLtP7Q7Ol0SAP3MLieJFdMhSAl1x5x2VRF8/s1600/regular+expression.png" /></span><b></b></a></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">
<span style="font-family: "microsoft yahei";">re.search 用法</span></span></h2>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">找出字串中含有我們要搜尋的字串並回傳</span></b><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; font-size: 18px; height: 80px; margin: 0px; padding-top: 8px; width: 600px;">m = re.search('bc', 'dfdljbabckle').group()
print(m)
</textarea><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">
<!--代碼區塊-->
</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">輸出結果</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgpUmhkOQwU1Fos05UYe_vLPHJG6c0-gEsuLDDSdYHnLf_K2WBgd5cInWlkGQh4l0-pHQi-7eIiv3O8uiYxegkiQas93LXrATPjZBFIiH1YxT87LPnirXEFn4tlet-5AUtm4zmqrGOvVQ/s1600/re+search.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="123" data-original-width="1002" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgpUmhkOQwU1Fos05UYe_vLPHJG6c0-gEsuLDDSdYHnLf_K2WBgd5cInWlkGQh4l0-pHQi-7eIiv3O8uiYxegkiQas93LXrATPjZBFIiH1YxT87LPnirXEFn4tlet-5AUtm4zmqrGOvVQ/s1600/re+search.png" /></span><b></b></a></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">
<span style="font-family: "microsoft yahei";">re.findall() 用法</span></span></h2>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">找出字串中含有ef的所有字串</span></b><br />
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<!--代碼區塊-->
<textarea font-family:monospace="" style="background-color: black; color: white; height: 80px; margin: 0px; padding-top: 8px; width: 600px;">m = re.findall('ef', 'dahdjadjkacefjxncjefcklsdnshef')
print(m)
</textarea><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">
<!--代碼區塊-->
</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">輸出結果</span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg710VQwbpe02ZnFOrx6QHcoM-VccZy46ofrTN5ZNBT5Hf3pZnRNhxFoA9neH2O0IGzDqLS2gNqDeIYjjpXiwmZBeuCJa4eOzhRPZ24tOIjibTeVBLDabhVjUvxXQ51mw_uBuWMvMhyphenhyphen4vI/s1600/re+findall.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="117" data-original-width="1004" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg710VQwbpe02ZnFOrx6QHcoM-VccZy46ofrTN5ZNBT5Hf3pZnRNhxFoA9neH2O0IGzDqLS2gNqDeIYjjpXiwmZBeuCJa4eOzhRPZ24tOIjibTeVBLDabhVjUvxXQ51mw_uBuWMvMhyphenhyphen4vI/s1600/re+findall.png" /></span><b></b></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">常見用的一些表達式的用法</span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><span style="background-color: #cccccc;"> . </span>(dot) 表示除了換行字元→\n </b><b>的任何字符</b></span></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> PS:一個 .(dot) 只會找一個字元</span></b><br />
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv96dp1plmWFfBenreHNNlFiAylE6AixfBYgvqk_oPsEEO1lV977nVwF1DE9HmArvksOrnF2qWWVEE3SLuiZhtVXxBJk1B26_tNlKK3uv3QrqALMQeHoQg7QP-wYaKMsr56-bMrWy-fto/s1600/regu+dot.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="118" data-original-width="1004" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv96dp1plmWFfBenreHNNlFiAylE6AixfBYgvqk_oPsEEO1lV977nVwF1DE9HmArvksOrnF2qWWVEE3SLuiZhtVXxBJk1B26_tNlKK3uv3QrqALMQeHoQg7QP-wYaKMsr56-bMrWy-fto/s1600/regu+dot.png" /></span><b></b></a></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
</div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background-color: #cccccc;"><b> ^ </b></span><b>指的是開頭要完全等於字元</b></span><br />
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXAdDTYO6YUEuCO__oBeLyu7kYhj1Q6hzbu4uo1vHCtBhzHgrPBH2kHOLBVXSw3_QHNX4KRuK3QDiY-a5HTjMJx-V7P1HVC7uEftumuqwrxwTRkMkY6pSBJxJGn_lghV-MGy4R8ZwBnzI/s1600/re+1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="138" data-original-width="998" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXAdDTYO6YUEuCO__oBeLyu7kYhj1Q6hzbu4uo1vHCtBhzHgrPBH2kHOLBVXSw3_QHNX4KRuK3QDiY-a5HTjMJx-V7P1HVC7uEftumuqwrxwTRkMkY6pSBJxJGn_lghV-MGy4R8ZwBnzI/s1600/re+1.png" /></span><b></b></a></div>
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b style="background-color: #cccccc;"> $ </b><b>只比對結尾字元</b></span></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxmW9uzObUNGchmATa5sQ38l152Z769BSUahr-22rLnRFvnoYXIg8-You2kmW7SorAtf8NH0sD_BDIWfio5p1sZCkxhePpLfUNihCBA8B4rEsHkFy0MD7ej1qg4Sd3HJqQ8ON9s0607Pw/s1600/re+%25E7%25B5%2590%25E5%25B0%25BE%25E5%25AD%2597%25E5%2585%2583.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="137" data-original-width="1001" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxmW9uzObUNGchmATa5sQ38l152Z769BSUahr-22rLnRFvnoYXIg8-You2kmW7SorAtf8NH0sD_BDIWfio5p1sZCkxhePpLfUNihCBA8B4rEsHkFy0MD7ej1qg4Sd3HJqQ8ON9s0607Pw/s1600/re+%25E7%25B5%2590%25E5%25B0%25BE%25E5%25AD%2597%25E5%2585%2583.png" /></span><b></b></a></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background-color: #cccccc;"> * </span>指的是0~N個字元</span></b><br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv8Myxe8OyoecudZUXKztgOTloBgdlLRCGXQmD_DUvetdyGgREA43m3JCULnwCc9iLWE0ABa9Zbevb3Wzt9Xo7yD9DDQzIDYZDK4ghgq9ORydL2KZ622NfkdGWJiNCFM_qE9eXHdm7AH0/s1600/re+2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="121" data-original-width="1003" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv8Myxe8OyoecudZUXKztgOTloBgdlLRCGXQmD_DUvetdyGgREA43m3JCULnwCc9iLWE0ABa9Zbevb3Wzt9Xo7yD9DDQzIDYZDK4ghgq9ORydL2KZ622NfkdGWJiNCFM_qE9eXHdm7AH0/s1600/re+2.png" /></span><b></b></a></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background-color: #cccccc;"><br /></span><span style="background-color: #cccccc;"><br /></span>
<span style="background-color: #cccccc;"> '+' </span> 指的是1~N個字元</span></b><br />
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg62jjED6FZI0ukIE6nJWIC5in13p6ksTL-cd30Lo-IdIyiMWd9R9eSFrm612GtaOXahUzvZjE0S7oPDAmXTTL3eqHLvNaT6wAC-6czzFfYEA6xL-PwuboeyY015jtXsq3vM-UPBX66qtM/s1600/re3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="132" data-original-width="998" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg62jjED6FZI0ukIE6nJWIC5in13p6ksTL-cd30Lo-IdIyiMWd9R9eSFrm612GtaOXahUzvZjE0S7oPDAmXTTL3eqHLvNaT6wAC-6czzFfYEA6xL-PwuboeyY015jtXsq3vM-UPBX66qtM/s1600/re3.png" /></span><b></b></a></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br />
<br />
<br />
<br />
<br /><br />
<span style="background-color: #cccccc;"> '?' </span> 指的是0或1個字符</span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOH_ZbiuJ0sPR_40ZAoK68KMC11I4yovncTQttxMpFYxq_Yt5scKdwgQj97Efhpd-JhtUp6F2y6fcdwLqOL8mAuIwp2E_UsTdqi44mm4zK9QuUEYDXqXYOJSgTmFBXuLRKFXyRSpzfzI/s1600/re+4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="169" data-original-width="1004" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKOH_ZbiuJ0sPR_40ZAoK68KMC11I4yovncTQttxMpFYxq_Yt5scKdwgQj97Efhpd-JhtUp6F2y6fcdwLqOL8mAuIwp2E_UsTdqi44mm4zK9QuUEYDXqXYOJSgTmFBXuLRKFXyRSpzfzI/s1600/re+4.png" /></span><b></b></a></div>
<div>
<span style="background-color: #cccccc; font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b><br />
</b></span></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background-color: #cccccc;"> '{m}' </span> 指的是要有m個連貫數量的字元。</span></b><br />
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBYueMBSlmw9Wc4QnZfJRFYPXirn6L1xSDTIPhyphenhyphenY7YV_xpBnhadENDfT_-pKn37dbdjJTfdiye_pzz8bM_7bbERV_0oK8O9TcYAIjXomFHW3zI5TsltoXsbEnB-3sOZV1grj259gFB880/s1600/re1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="135" data-original-width="1000" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBYueMBSlmw9Wc4QnZfJRFYPXirn6L1xSDTIPhyphenhyphenY7YV_xpBnhadENDfT_-pKn37dbdjJTfdiye_pzz8bM_7bbERV_0oK8O9TcYAIjXomFHW3zI5TsltoXsbEnB-3sOZV1grj259gFB880/s1600/re1.png" /></span><b></b></a></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background-color: #cccccc;">'{m,n}'</span> 指的是要有m~n個數量的字元。</span></b><br />
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPnmxBC1iKCqRjWimw3_d3_xVGhXH7TW9gsNsBgKLnwfRcRU-WOFp065yjAaZ3Rw2Vk5muN-iixEp7Td6c9Vl1q6pnAME9KCHLp4RbwwWPPuv40PS6HoRsAxuAn40DSfwKQacOyv-Ia6M/s1600/re2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="clear: left; float: left; font-family: "arial" , "helvetica" , sans-serif; font-size: large; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="150" data-original-width="1001" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPnmxBC1iKCqRjWimw3_d3_xVGhXH7TW9gsNsBgKLnwfRcRU-WOFp065yjAaZ3Rw2Vk5muN-iixEp7Td6c9Vl1q6pnAME9KCHLp4RbwwWPPuv40PS6HoRsAxuAn40DSfwKQacOyv-Ia6M/s1600/re2.png" /></span><b></b></a></div>
<div>
<b style="background-color: #cccccc;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background-color: #cccccc;">'\' </span><span style="background-color: #cccccc;">'\'<span style="color: rgba(0 , 0 , 0 , 0.84); letter-spacing: -0.063px;"> </span></span>指的是字元跳脫,如果要找特殊字元時,可以使用跳脫字元的方式來搜索</span></b><br />
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRW2FK4mlpsjk9PVX-q6aOEJYdQG6TTS-xFbiubwIKnY7nWUR2ovC1GhS3e7gb2rtg8aC7rvNm-WTamjFcfD3FVVrajSBanlp6pX4cBBbZ-YWrj5piXUJnVPao_j-TQSloAfAYiU-BjIE/s1600/re4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><img border="0" data-original-height="96" data-original-width="1002" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRW2FK4mlpsjk9PVX-q6aOEJYdQG6TTS-xFbiubwIKnY7nWUR2ovC1GhS3e7gb2rtg8aC7rvNm-WTamjFcfD3FVVrajSBanlp6pX4cBBbZ-YWrj5piXUJnVPao_j-TQSloAfAYiU-BjIE/s1600/re4.png" /></span></b></a></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background-color: #cccccc;">'[ ]'</span> 指的是要搜索一定範圍內的字元,例如:</span></b><br />
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi05M2hyGqFmN5DMw7YP6j8u9GxeCw6jLjjrpxV47HCrMn4EEA3w9VswcS0V0kXArxPEC2YRZXOKEay_mPu2hS01bCqWv8kt4PEU2FXAYASu3XeKetbzdj3awmxOEXSi1hHv9spFrp0vL8/s1600/re5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><img border="0" data-original-height="116" data-original-width="1003" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi05M2hyGqFmN5DMw7YP6j8u9GxeCw6jLjjrpxV47HCrMn4EEA3w9VswcS0V0kXArxPEC2YRZXOKEay_mPu2hS01bCqWv8kt4PEU2FXAYASu3XeKetbzdj3awmxOEXSi1hHv9spFrp0vL8/s1600/re5.png" /></span></b></a></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT7FAEls8hQvVF07UNNBoklt_JUG_XN4swqLtR9GpPM0jWz6NLTRQZwi_k07VPHSRHiU2xuDE5FPByHxdsEW1fj0xefA1QuDc6A4OQHxNHNsoSMl8ta0HCEsgsnkhyphenhyphenwcKX46b9fpw0TZM/s1600/re6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><img border="0" data-original-height="119" data-original-width="1001" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT7FAEls8hQvVF07UNNBoklt_JUG_XN4swqLtR9GpPM0jWz6NLTRQZwi_k07VPHSRHiU2xuDE5FPByHxdsEW1fj0xefA1QuDc6A4OQHxNHNsoSMl8ta0HCEsgsnkhyphenhyphenwcKX46b9fpw0TZM/s1600/re6.png" /></span></b></a></div>
<div>
<div>
<br /></div>
<!--標題區塊--> <!--字形更改font-family:-->
<br />
<h2 style="background-color: white; border-color: rgb(138, 190, 183); border-radius: 2px; border-style: solid; border-width: 1px 1px 1px 15px; box-sizing: border-box; color: #0b5394; display: inline-block; letter-spacing: 1.4px; line-height: 1.1; margin: 20px 0px; padding: 7px; position: relative;">
<span style="font-family: "microsoft yahei";">檢測regular expression Tool</span></h2>
<!--標題區塊-->
</div>
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">大家如果想要知道自己有沒有寫隊可以使用這個工具→<a href="https://regexr.com/41vj9">https://regexr.com/41vj9</a></span></b>
<br /></div>
王瑞士http://www.blogger.com/profile/06639009859864467161noreply@blogger.com0