<?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>網頁爬蟲 &#8211; 龍冥 Blog</title>
	<atom:link href="https://dragongo.co/tag/%e7%b6%b2%e9%a0%81%e7%88%ac%e8%9f%b2/feed/" rel="self" type="application/rss+xml" />
	<link>https://dragongo.co</link>
	<description>Code &#38; Read</description>
	<lastBuildDate>Fri, 21 May 2021 03:42:42 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.7</generator>

<image>
	<url>https://dragongo.co/wp-content/uploads/2021/05/cropped-cropped-LOGO-2-e1655437907165-32x32.png</url>
	<title>網頁爬蟲 &#8211; 龍冥 Blog</title>
	<link>https://dragongo.co</link>
	<width>32</width>
	<height>32</height>
</image> 
	<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>在開始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>若輸出結果為，即為安裝完成！</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>相關參考資料：<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><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>若沒有安裝過lxml解析器，需先透過指令安裝</p>


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



<p>前兩行先將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類別中為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>
