<?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>seo 彙整 - 台大系統訓練班課程網頁 (林奇賦)</title>
	<atom:link href="http://cflin.com/wordpress/tag/seo/feed" rel="self" type="application/rss+xml" />
	<link>http://cflin.com/wordpress</link>
	<description>台大系統訓練班 python 課程相關資料</description>
	<lastBuildDate>Tue, 05 Dec 2017 07:17:45 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8.3</generator>

<image>
	<url>http://cflin.com/wordpress/wp-content/uploads/2017/12/cropped-2000px-Python-logo-notext.svg_-32x32.png</url>
	<title>seo 彙整 - 台大系統訓練班課程網頁 (林奇賦)</title>
	<link>http://cflin.com/wordpress</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Google關鍵字搜尋，將搜尋結果排名紀錄下來</title>
		<link>http://cflin.com/wordpress/566/google%e9%97%9c%e9%8d%b5%e5%ad%97%e6%90%9c%e5%b0%8b%ef%bc%8c%e5%b0%87%e6%90%9c%e5%b0%8b%e7%b5%90%e6%9e%9c%e6%8e%92%e5%90%8d%e7%b4%80%e9%8c%84%e4%b8%8b%e4%be%86</link>
					<comments>http://cflin.com/wordpress/566/google%e9%97%9c%e9%8d%b5%e5%ad%97%e6%90%9c%e5%b0%8b%ef%bc%8c%e5%b0%87%e6%90%9c%e5%b0%8b%e7%b5%90%e6%9e%9c%e6%8e%92%e5%90%8d%e7%b4%80%e9%8c%84%e4%b8%8b%e4%be%86#respond</comments>
		
		<dc:creator><![CDATA[Chifu]]></dc:creator>
		<pubDate>Fri, 01 Dec 2017 03:38:03 +0000</pubDate>
				<category><![CDATA[Python範例]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[seo]]></category>
		<guid isPermaLink="false">http://cflin.com/wordpress/?p=566</guid>

					<description><![CDATA[<p>使用Python撰寫自動化搜尋特定關鍵字 Google關鍵字搜尋將搜尋結果排名紀錄下來 Selenium 使用 Chrome 瀏覽器 webdriver SEO (Search Engine Optimization)，是維護網站非常重要的一項工作，利用這個小程式可以自動化的搜尋關鍵字，並將搜尋排名結果存入檔案，以利分析成效與後續的持續優化。 需要先安裝 selenium 套件 下載 Chrome 瀏覽器 webdriver 額外會需要用到兩隻檔案，需要先建立好放置於py檔同層資料夾下 site.csv : 裡面放要搜尋的網站位置 terms.csv : 搜尋關鍵字 相關API參考</p>
<p>這篇文章 <a rel="nofollow" href="http://cflin.com/wordpress/566/google%e9%97%9c%e9%8d%b5%e5%ad%97%e6%90%9c%e5%b0%8b%ef%bc%8c%e5%b0%87%e6%90%9c%e5%b0%8b%e7%b5%90%e6%9e%9c%e6%8e%92%e5%90%8d%e7%b4%80%e9%8c%84%e4%b8%8b%e4%be%86">Google關鍵字搜尋，將搜尋結果排名紀錄下來</a> 最早出現於 <a rel="nofollow" href="http://cflin.com/wordpress">台大系統訓練班課程網頁 (林奇賦)</a>。</p>
]]></description>
										<content:encoded><![CDATA[<h1>使用Python撰寫自動化搜尋特定關鍵字</h1>
<p>Google關鍵字搜尋將搜尋結果排名紀錄下來</p>
<p><a href="https://learngeb-ebook.readbook.tw/intro/selenium.html" target="_blank" rel="noopener noreferrer">Selenium</a> 使用 Chrome 瀏覽器 <a href="https://sites.google.com/a/chromium.org/chromedriver/downloads" target="_blank" rel="noopener noreferrer">webdriver</a></p>
<p>SEO (Search Engine Optimization)，是維護網站非常重要的一項工作，利用這個小程式可以自動化的搜尋關鍵字，並將搜尋排名結果存入檔案，以利分析成效與後續的持續優化。</p>
<p>需要先安裝 selenium 套件</p>
<p>下載 Chrome 瀏覽器 <a href="https://sites.google.com/a/chromium.org/chromedriver/downloads" target="_blank" rel="noopener noreferrer">webdriver</a></p>
<p>額外會需要用到兩隻檔案，需要先建立好放置於py檔同層資料夾下</p>
<p>site.csv : 裡面放要搜尋的網站位置</p>
<p>terms.csv : 搜尋關鍵字</p>
<pre class="brush: python; title: ; notranslate">
from selenium import webdriver
import csv
import time

chromedriver = &quot;/Users/chifu/Documents/chromedriver&quot;
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(&quot;--incognito&quot;)
driver = webdriver.Chrome(chromedriver, chrome_options=chrome_options)
csvr_site = csv.reader(open('site.csv', 'r'))
csvr_terms = csv.reader(open('terms.csv', 'r'))
outfile = open('rank.csv', 'w')
csvwriter = csv.writer(outfile)
search_pages = 5

for s in csvr_site:
	site = s[0]

for row in csvr_terms:
	print(row[0])
	current_page = 1
	while current_page &amp;amp;amp;lt;= search_pages:
		if current_page == 1:
			driver.get(&quot;https://www.google.com.tw/search?q=%s&quot; % row[0])
		else:
			driver.get(next_pageurl)
		time.sleep(1)
		doms = driver.find_elements_by_css_selector(&quot;div.rc h3.r a&quot;)
		next_pageurl = driver.find_element_by_css_selector(&quot;a#pnnext.pn&quot;).get_attribute(&quot;href&quot;)
		counter = 0
		rank = &quot;not found&quot;
		for dom in doms:
			counter += 1	
			href = dom.get_attribute(&quot;href&quot;)
			if site in href:
				rank = counter
				break
		if rank != &quot;not found&quot;:
			break
		current_page += 1

	csvwriter.writerow([row[0], current_page, rank])
	outfile.flush()
	time.sleep(1)
driver.close()
</pre>
<p>相關<a href="http://selenium-python.readthedocs.io/api.html" target="_blank" rel="noopener noreferrer">API參考</a></p>
<p>這篇文章 <a rel="nofollow" href="http://cflin.com/wordpress/566/google%e9%97%9c%e9%8d%b5%e5%ad%97%e6%90%9c%e5%b0%8b%ef%bc%8c%e5%b0%87%e6%90%9c%e5%b0%8b%e7%b5%90%e6%9e%9c%e6%8e%92%e5%90%8d%e7%b4%80%e9%8c%84%e4%b8%8b%e4%be%86">Google關鍵字搜尋，將搜尋結果排名紀錄下來</a> 最早出現於 <a rel="nofollow" href="http://cflin.com/wordpress">台大系統訓練班課程網頁 (林奇賦)</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>http://cflin.com/wordpress/566/google%e9%97%9c%e9%8d%b5%e5%ad%97%e6%90%9c%e5%b0%8b%ef%bc%8c%e5%b0%87%e6%90%9c%e5%b0%8b%e7%b5%90%e6%9e%9c%e6%8e%92%e5%90%8d%e7%b4%80%e9%8c%84%e4%b8%8b%e4%be%86/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
