This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup as bs | |
#NBA網址 | |
res = requests.get('https://www.ptt.cc/bbs/NBA/index.html') | |
#用lxml’s HTML parser直接解析html的tag | |
soup = bs(res.text,'lxml') | |
#建議看完就把它comment掉省記憶體 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#載入這次需要的所有套件和function | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import time | |
#安裝chrome WebDriver瀏覽器驅動程式 | |
#https://chromedriver.chromium.org/downloads (注意先確認自己的chrome版本) | |
#下載到自己指定的存放位置,並解壓縮 | |
chrome_driver_path = '填入自己的下載檔的檔案位置' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://technews.tw/ | |
#爬取內容請以當日網頁為準 | |
#第一階段 | |
import requests | |
from bs4 import BeautifulSoup as bs | |
import json | |
res = requests.get('https://technews.tw/') | |
soup = bs(res.text,'lxml') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#載入套件 | |
#API: https://www.dcard.tw/service/api/v2/forums | |
import pandas as pd | |
import requests | |
r = requests.get('https://www.dcard.tw/service/api/v2/forums') | |
response = r.text | |
import json | |
data = json.loads(response) | |
#是線上api所以可以直接以json型態下載 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#載入selenium套件 | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import time | |
#我的chromedriver路徑 | |
chrome_driver_path = '/Users/ting11222001/Downloads/chromedriver' | |
#第一個頁面的url | |
url = 'https://gogakuru.com/english/phrase/genre/180_%E5%88%9D%E7%B4%9A%E3%83%AC%E3%83%99%E3%83%AB.html?layoutPhrase=1&orderPhrase=1&condMovie=0&flow=enSearchGenre&condGenre=180&perPage=50' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !pip install PyMySQL | |
import pymysql | |
#連結自己架在Virtual Box (Centos 7) 的mariadb | |
conn = pymysql.connect(host = '192.168.56.123', | |
user = 'tiffany', | |
passwd = "admin123", | |
db = 'demo_2020_pyscrap') | |
#創一個cursor物件,是在資料庫操作的游標 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import libraries | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import seaborn as sns | |
%matplotlib inline | |
# import dataset from: https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_boston.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib notebook | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from skimage.feature import match_template | |
from PIL import Image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# convert image into an array and ndim: 3 | |
ImagenTotal = np.asarray(Image.open('./redmangos.jpg')) | |
# print(ImagenTotal.ndim) | |
#output: 3 | |
# print(ImagenTotal.shape) | |
#output: (480, 640, 3) | |
# print(len(ImagenTotal)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Interactive selection of points | |
# store all clicked coordinates here | |
puntosinteres = [] | |
# Create a new figure: width, height in inches | |
fig = plt.figure(figsize=(5, 4)) | |
# position figure to 1st row, 1st column, index = 1 | |
ax = fig.add_subplot(111) |
OlderNewer