發表文章

目前顯示的是有「網路爬蟲」標籤的文章

教你不用寫程式也能爬網路上的資料

圖片
要分析資料, 有時候需要用到網路上的資料, 這時就需要爬資料. 爬資料有很多種方式, 一般會用R 或Python 寫爬蟲程式來爬取資料. 今天教大家不用寫程式也能爬網路資料 只要用google sheets 一步就搞定. 如果我們想要知道今天 集中市場前10大進出券商淨買賣超前30名個股是那些, 一般我們都要google 去找, 或上網到某特定網站去點選查找, 如果想要紀錄分析就還要copy paste 的動作, 現在這些通通免了, 只要開啟google sheets 每天最新的資料就自動出現了~~~ 趕快來看怎麼做ㄅ…. 比如: 我們要爬取 https://www.cnyes.com/twstock/idx_main2/0000T.htm 裡的資料 開啟 google sheets 在任一cell內輸入: =IMPORTHTML("https://www.cnyes.com/twstock/idx_main2/0000T.htm","table",2) 輸入完後按enter 就完成了 存檔後, 每天一開啟這個檔案, 甚麼都不用做,最新的資料就自動show 在眼前, 是不是很方便?

用google sheets 連結下載網路csv檔案資料

圖片
用google sheets中的IMPORTDATA功能來連結下載網路上的csv 檔案資料, 來分析 1. 先到有csv 檔案資料的網站, 以下舉政府公開資料網站為例: https://data.gov.tw/dataset/5977 在要下載的CSV檔案圖示下按滑鼠右鍵,選擇複製連結網址 開啟google sheets, 並輸入: =IMPORTDATA("按ctrl_V貼上剛才的網址"), 如下圖所示 =IMPORTDATA(" http://www.epza.gov.tw/pagedownloadfile.aspx?fid=a8475f8a4ebc4e17 ") 按enter 即可抓取下載該筆資料:

python BeautifulSoup

圖片
from urllib.request import urlopen from bs4 import BeautifulSoup import re In [155]: h = urlopen ( "http://www.pythonscraping.com/pages/page3.html" ) In [156]: hb = BeautifulSoup ( h ) C:\Users\peter\Anaconda3\lib\site-packages\bs4\__init__.py:181: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently. The code that caused this warning is on line 184 of the file C:\Users\peter\Anaconda3\lib\runpy.py. To get rid of this warning, change code that looks like this: BeautifulSoup([your markup]) to this: BeautifulSoup([your markup], "lxml") markup_type=markup_type)) In [157]: print ( hb ) Totally Normal Gifts Here is a collection o...