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

<channel>
	<title>beautifulsoup &#8211; 龍冥 Blog</title>
	<atom:link href="https://dragongo.co/tag/beautifulsoup/feed/" rel="self" type="application/rss+xml" />
	<link>https://dragongo.co</link>
	<description>Code &#38; Read</description>
	<lastBuildDate>Fri, 21 May 2021 14:43:06 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.5</generator>

<image>
	<url>https://dragongo.co/wp-content/uploads/2021/05/cropped-cropped-LOGO-2-e1655437907165-32x32.png</url>
	<title>beautifulsoup &#8211; 龍冥 Blog</title>
	<link>https://dragongo.co</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Python網頁爬蟲：正規表示式</title>
		<link>https://dragongo.co/python/</link>
		
		<dc:creator><![CDATA[龍冥]]></dc:creator>
		<pubDate>Fri, 21 May 2021 14:42:07 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[beautifulsoup]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[requests]]></category>
		<category><![CDATA[正規表示式]]></category>
		<category><![CDATA[自學程式]]></category>
		<guid isPermaLink="false">https://dragongo.co/?p=1233</guid>

					<description><![CDATA[完整的正規表示式請點超連結 這程式爬莫煩開發的測&#8230;]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">完整的<a href="https://dragongo.co/python%e6%ad%a3%e8%a6%8f%e8%a1%a8%e7%a4%ba%e5%bc%8fregular-expression/" target="_blank" data-type="URL" data-id="https://dragongo.co/python%e6%ad%a3%e8%a6%8f%e8%a1%a8%e7%a4%ba%e5%bc%8fregular-expression/" rel="noreferrer noopener" class="rank-math-link">正規表示式</a>請點超連結</p>



<p class="wp-block-paragraph">這程式爬莫煩開發的<a href="https://mofanpy.com/static/scraping/table.html" target="_blank" data-type="URL" data-id="https://mofanpy.com/static/scraping/table.html" rel="noreferrer noopener" class="rank-math-link">測試網站</a>，目標爬出此網頁的圖片(img)連結，以及爬出href標籤內的超連結。</p>



<pre class="wp-block-code"><code># %%
from bs4 import BeautifulSoup
from urllib.request import urlopen
import re

# if has Chinese, apply decode()
#html = urlopen("https://mofanpy.com/static/scraping/basic-structure.html").read().decode('utf-8')
html = urlopen("https://mofanpy.com/static/scraping/table.html").read().decode('utf-8')
print(html)

# %%
soup = BeautifulSoup(html , features='lxml')
#print(soup)
img_links = soup.find_all("img",{"src": re.compile('.*?\.jpg')})
for link in img_links:
    print(link&#91;'src'])

# %%
course_links = soup.find_all('a', {'href': re.compile('/tutorials.*')})
for link in course_links:
    print(link&#91;'href'])</code></pre>



<p class="wp-block-paragraph">顯示結果</p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html>
&lt;html lang="cn">
&lt;head>
        &lt;meta charset="UTF-8">
        &lt;title>爬虫练习 表格 table | 莫烦 Python&lt;/title>

        &lt;style>
        img {
                width: 250px;
        }
        table{
                width:50%;
        }
        td{
                margin:10px;
                padding:15px;
        }
        &lt;/style>
&lt;/head>
&lt;body>

&lt;h1>表格 爬虫练习&lt;/h1>

&lt;p>这是一个在 &lt;a href="/" >莫烦 Python&lt;/a> 的 &lt;a href="/tutorials/data-manipulation/scraping/" >爬虫教程&lt;/a>
        里无敌简单的网页, 所有的 code 让你一目了然, 清晰无比.&lt;/p>

&lt;br>
&lt;table id="course-list">
        &lt;tr>
                &lt;th>
                        分类
                &lt;/th>&lt;th>
                        名字
                &lt;/th>&lt;th>
                        时长
                &lt;/th>&lt;th>
                        预览
                &lt;/th>
        &lt;/tr>

        &lt;tr id="course1" class="ml">
                &lt;td>
                        机器学习
                &lt;/td>&lt;td>
                        &lt;a href="/tutorials/machine-learning/tensorflow/">
                                Tensorflow 神经网络&lt;/a>
                &lt;/td>&lt;td>
                        2:00
                &lt;/td>&lt;td>
                        &lt;img src="/static/img/course_cover/tf.jpg">
                &lt;/td>
        &lt;/tr>

        &lt;tr id="course2" class="ml">
                &lt;td>
                        机器学习
                &lt;/td>&lt;td>
                        &lt;a href="/tutorials/machine-learning/reinforcement-learning/">
                                强化学习&lt;/a>
                &lt;/td>&lt;td>
                        5:00
                &lt;/td>&lt;td>
                        &lt;img src="/static/img/course_cover/rl.jpg">
                &lt;/td>
        &lt;/tr>

        &lt;tr id="course3" class="data">
                &lt;td>
                        数据处理
                &lt;/td>&lt;td>
                        &lt;a href="/tutorials/data-manipulation/scraping/">
                                爬虫&lt;/a>
                &lt;/td>&lt;td>
                        3:00
                &lt;/td>&lt;td>
                        &lt;img src="/static/img/course_cover/scraping.jpg">
                &lt;/td>
        &lt;/tr>

&lt;/table>

&lt;/body>
&lt;/html>
/static/img/course_cover/tf.jpg
/static/img/course_cover/rl.jpg
/static/img/course_cover/scraping.jpg
/tutorials/data-manipulation/scraping/
/tutorials/machine-learning/tensorflow/
/tutorials/machine-learning/reinforcement-learning/
/tutorials/data-manipulation/scraping/</code></pre>



<p class="wp-block-paragraph">資料來源：<a href="https://mofanpy.com/tutorials/data-manipulation/scraping/beautifulsoup-regex/" target="_blank" data-type="URL" data-id="https://mofanpy.com/tutorials/data-manipulation/scraping/beautifulsoup-regex/" rel="noreferrer noopener" class="rank-math-link">莫煩-BeautifulSoup 解析網頁: 正則表達</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>安裝BeautifulSoup教學(環境：Visual Studio Code)</title>
		<link>https://dragongo.co/%e5%ae%89%e8%a3%9dbeatifulsoup%e6%95%99%e5%ad%b8%e7%92%b0%e5%a2%83%ef%bc%9avisula-studio-code/</link>
					<comments>https://dragongo.co/%e5%ae%89%e8%a3%9dbeatifulsoup%e6%95%99%e5%ad%b8%e7%92%b0%e5%a2%83%ef%bc%9avisula-studio-code/#comments</comments>
		
		<dc:creator><![CDATA[龍冥]]></dc:creator>
		<pubDate>Sat, 15 May 2021 01:00:00 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[beautifulsoup]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[visual studio code]]></category>
		<category><![CDATA[網頁爬蟲]]></category>
		<category><![CDATA[自學程式]]></category>
		<guid isPermaLink="false">https://dragongo.co/?p=980</guid>

					<description><![CDATA[教你如何在visual studio code下安裝beautifulsoup。]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<p class="wp-block-paragraph">在開始python網頁爬蟲之前，需要先安裝其分析模組和取樣模組。</p>



<ol class="wp-block-list"><li>開啟visual studio code的終端機介面。</li><li>使用<a aria-label="pip (opens in a new tab)" href="https://officeguide.cc/windows-install-python-pip-tutorial-2019/" target="_blank" rel="noreferrer noopener" class="rank-math-link">pip</a>指令安裝beautifulsoup4，其目的是用來分析html資料。<ul><li>pip install beautifulsoup4</li><li>C:\Users\User\AppData\Local\Programs\Python\Python39\Scripts</li><li>(若遇到「<a href="https://dragongo.co/%e8%a7%a3%e6%b1%ba%ef%bc%9a%e7%84%a1%e6%b3%95%e8%be%a8%e8%ad%98-pip-%e8%a9%9e%e5%bd%99%e6%98%af%e5%90%a6%e7%82%ba-cmdlet%e3%80%81%e5%87%bd%e6%95%b8%e3%80%81%e6%8c%87%e4%bb%a4%e6%aa%94%e6%88%96/" target="_blank" rel="noreferrer noopener">無法辨識 ‘pip’ 詞彙是否為 Cmdlet、函數、指令檔或可執行程式的名稱。請檢查名稱拼字是否正確，如果包含路徑的話，請確認路徑是否正確，然後再試一次。</a>」錯誤的話，請點及超連結)</li></ul></li><li>使用pip指令安裝python的requests套件，其目的是將html資料抓回來顯示。<ul><li>pip install requests</li></ul></li><li>嘗試執行以下程式碼，其程式目的是將莫凡提供的<a aria-label=" (opens in a new tab)" href="https://mofanpy.com/static/scraping/basic-structure.html" target="_blank" rel="noreferrer noopener" class="rank-math-link">基礎網頁</a>抓下來顯示其程式碼。</li></ol>



<pre><code class="python">import requests
from bs4 import BeautifulSoup

res = requests.get("https://mofanpy.com/static/scraping/basic-structure.html")
soup = BeautifulSoup(res.text, "html.parser")
print(soup.prettify())  #輸出排版後的HTML內容5x
</code></pre>



<p class="wp-block-paragraph">若輸出結果為，即為安裝完成！</p>



<pre class="wp-block-code"><code>&lt;!DOCTYPE html&gt;
&lt;html lang="cn"&gt;
 &lt;head&gt;
  &lt;meta charset="utf-8"/&gt;
  &lt;title&gt;
   Scraping tutorial 1 | 莫烦Python
  &lt;/title&gt;
  &lt;link href="{{ static_url }}/js/description/tab_icon.png" rel="icon"/&gt;
 &lt;/head&gt;
 &lt;body&gt;
  &lt;h1&gt;
   爬虫测试1
  &lt;/h1&gt;
  &lt;p&gt;
   这是一个在
   &lt;a href="/"&gt;
    莫烦Python
   &lt;/a&gt;
   &lt;a href="/tutorials/data-manipulation/scraping/"&gt;
    爬虫教程
   &lt;/a&gt;
   中的简单测试.
  &lt;/p&gt;
 &lt;/body&gt;
&lt;/html&gt;</code></pre>
</div></div>



<figure class="wp-block-image size-large is-style-default"><img fetchpriority="high" decoding="async" width="1024" height="683" src="https://dragongo.co/wp-content/uploads/2021/05/image-4-1024x683.png" alt="image 4" class="wp-image-983" title="安裝BeautifulSoup教學(環境：Visual Studio Code) 1" srcset="https://dragongo.co/wp-content/uploads/2021/05/image-4-1024x683.png 1024w, https://dragongo.co/wp-content/uploads/2021/05/image-4-300x200.png 300w, https://dragongo.co/wp-content/uploads/2021/05/image-4-768x512.png 768w, https://dragongo.co/wp-content/uploads/2021/05/image-4-1536x1024.png 1536w, https://dragongo.co/wp-content/uploads/2021/05/image-4-1140x760.png 1140w, https://dragongo.co/wp-content/uploads/2021/05/image-4.png 1800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<figure class="wp-block-image size-large is-style-default"><img decoding="async" width="1024" height="683" src="https://dragongo.co/wp-content/uploads/2021/05/image-5-1024x683.png" alt="image 5" class="wp-image-985" title="安裝BeautifulSoup教學(環境：Visual Studio Code) 2" srcset="https://dragongo.co/wp-content/uploads/2021/05/image-5-1024x683.png 1024w, https://dragongo.co/wp-content/uploads/2021/05/image-5-300x200.png 300w, https://dragongo.co/wp-content/uploads/2021/05/image-5-768x512.png 768w, https://dragongo.co/wp-content/uploads/2021/05/image-5-1536x1024.png 1536w, https://dragongo.co/wp-content/uploads/2021/05/image-5-1140x760.png 1140w, https://dragongo.co/wp-content/uploads/2021/05/image-5.png 1800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">相關參考資料：<br><a aria-label="[Python爬蟲教學]7個Python使用BeautifulSoup開發網頁爬蟲的實用技巧 (opens in a new tab)" href="https://www.learncodewithmike.com/2020/02/python-beautifulsoup-web-scraper.html" target="_blank" rel="noreferrer noopener" class="rank-math-link">[Python爬蟲教學]7個Python使用BeautifulSoup開發網頁爬蟲的實用技巧</a><br><a aria-label="BeautifulSoup中文官方資料 (opens in a new tab)" href="https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/" target="_blank" rel="noreferrer noopener" class="rank-math-link">BeautifulSoup中文官方資料</a><br><a href="https://mofanpy.com/tutorials/data-manipulation/scraping/beautifulsoup-basic/" target="_blank" aria-label="BeautifulSoup 解析網頁: 基礎 (opens in a new tab)" rel="noreferrer noopener" class="rank-math-link">BeautifulSoup 解析網頁: 基礎</a></p>



<p class="wp-block-paragraph"><br></p>
]]></content:encoded>
					
					<wfw:commentRss>https://dragongo.co/%e5%ae%89%e8%a3%9dbeatifulsoup%e6%95%99%e5%ad%b8%e7%92%b0%e5%a2%83%ef%bc%9avisula-studio-code/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>如何使用Python的BeautifulSoup模組分析網頁中的標籤(CSS)？</title>
		<link>https://dragongo.co/%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python%e7%9a%84beautifulsoup%e6%a8%a1%e7%b5%84%e5%88%86%e6%9e%90%e7%b6%b2%e9%a0%81%e4%b8%ad%e7%9a%84%e6%a8%99%e7%b1%a4css%ef%bc%9f/</link>
		
		<dc:creator><![CDATA[龍冥]]></dc:creator>
		<pubDate>Fri, 14 May 2021 12:30:13 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[beautifulsoup]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[visual studio code]]></category>
		<category><![CDATA[網頁爬蟲]]></category>
		<category><![CDATA[自學程式]]></category>
		<guid isPermaLink="false">https://dragongo.co/?p=1007</guid>

					<description><![CDATA[講解如何用python的BeautifulSoup模組，找出網頁中特定的類別(class)。]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">若沒有安裝過lxml解析器，需先透過指令安裝</p>


<pre><code class="python">pip install lxml</code></pre>



<p class="wp-block-paragraph">前兩行先將BeautifulSoup以及urlopen函示庫匯入，因為網頁中包含中文字，因此讀取後會需要decode(&#8216;utf-8&#8217;)編碼。<br>再將html資料將其印出，網站來源為<a href="https://mofanpy.com/tutorials/data-manipulation/scraping/beautifulsoup-css/" target="_blank" aria-label="莫凡python (opens in a new tab)" rel="noreferrer noopener" class="rank-math-link">莫凡python</a>提供的<a href="https://mofanpy.com/static/scraping/list.html" target="_blank" aria-label="測試網站 (opens in a new tab)" rel="noreferrer noopener" class="rank-math-link">測試網站</a></p>



<pre><code class="python">from bs4 import BeautifulSoup
from urllib.request import urlopen

# if has Chinese, apply decode()
html = urlopen("https://mofanpy.com/static/scraping/list.html").read().decode('utf-8')

print(html)</code></pre>



<p class="wp-block-paragraph">這段程式碼將class類別中為month的資料解析出來，並透過print(m.get_text())將有使用month這個類別的標籤全部顯示。</p>



<pre><code class="python">from bs4 import BeautifulSoup
from urllib.request import urlopen

# if has Chinese, apply decode()
html = urlopen("https://mofanpy.com/static/scraping/list.html").read().decode('utf-8')
# use class to narrow search
#尋找指定的class類別
soup = BeautifulSoup(html, features='lxml')
month = soup.find_all('li',{"class":"month"})
for m in month:
    print(m.get_text())</code></pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
