def crash0(): print("現金回饋") options = Options() options.add_argument("--disable-notifications") usr = "******" chrome = webdriver.Chrome( 'C:/Users/USER/OneDrive/桌面/信用卡推薦系統_爬蟲程式/chromedriver.exe', chrome_options=options) chrome.get(usr) #利用class_name 來定位所要抓取的部分 #在該網頁中,results-list-view,是放置所有信用卡資訊的 div 的 class name container = chrome.find_element_by_class_name("results-list-view") # 因為每次加載一批新的隱藏資訊,都是以10個為一組 num_card = get_num_of_card(usr) for i in range(int(num_card / 10)): #移動到該元素(container)(即目前顯示的資訊)的底部(false) chrome.execute_script("arguments[0].scrollIntoView(false);", container) #在終端機上顯示,以便確定網頁有在,依所要的指示操作 print(i, ": ", "move to the bottom of container") #滾輪下滑1000 #因為移至「目前已顯示資訊的最底部」還不夠,還要再用滾輪往下滑一段距離,才會加載出一批新的資訊 chrome.execute_script("window.scrollBy(0,1000)") print("ok") #留時間給網頁載入(迴圈的) time.sleep(1) time.sleep(1) ############################inf_all#################################### #利用函式 get_inf_all 輸出「篩選條件:現金回饋」 所有信用卡資訊 inf_all = get_inf_all(chrome.page_source) titles = ["銀行", "信用卡", "年費", "國外現金回饋", "國內現金回饋"] print(titles) print() #因為該部分有問題,且是沒有規律的,所以,拿出來個別處理 inf_all[115][1] = "昇利卡" inf_all[125][1] = "亞洲萬里通聯名白金卡" #印出結果 print(inf_all) chrome.close() return inf_all
def crash1(): print("哩程") usr = "******" options = Options() options.add_argument("--disable-notifications") chrome = webdriver.Chrome( 'C:/Users/USER/OneDrive/桌面/信用卡推薦系統_爬蟲程式/chromedriver.exe', chrome_options=options) chrome.get(usr) #利用class_name 來定位所要抓取的部分 #在該網頁中,results-list-view,是放置所有信用卡資訊的 div 的 class name container = chrome.find_element_by_class_name("results-list-view") num_card = get_num_of_card(usr) for i in range(int(num_card / 10)): #移動到該元素(container)(即目前顯示的資訊)的底部(false) chrome.execute_script("arguments[0].scrollIntoView(false);", container) #在終端機上顯示,以便確定網頁有在,依所要的指示操作 print(i, ": ", "move to the bottom of container") #滾輪下滑1000 #因為移至「目前已顯示資訊的最底部」還不夠,還要再用滾輪往下滑一段距離,才會加載出一批新的資訊 chrome.execute_script("window.scrollBy(0,1000)") print("ok") #留時間給網頁載入(迴圈的) time.sleep(1) time.sleep(1) ############################inf_all#################################### data = chrome.page_source #i = 4,6,8,28 有問題 inf_all = get_inf_all_1(data) inf_all[4][1] = '亞洲萬里通聯名世界卡' inf_all[6][1] = '亞洲萬里通聯名世界卡' inf_all[8][1] = '亞洲萬里通聯名世界卡' inf_all[28][1] = '亞洲萬里通聯名世界卡' titles = ["銀行", "信用卡", "年費", "國外哩程回饋", "國內哩程回饋"] print(titles) print(inf_all) chrome.close() return inf_all
def crash8(): print("亞洲萬里通") usr = '******' options = Options() options.add_argument("--disable-notifications") chrome = webdriver.Chrome('D:\\coding_project\\project\\credit_card_analize_project\\Server\\updateData\\chromedriver.exe', chrome_options=options) chrome.get(usr) #利用class_name 來定位所要抓取的部分 #在該網頁中,results-list-view,是放置所有信用卡資訊的 div 的 class name container = chrome.find_element_by_class_name("results-list-view") num_card = get_num_of_card(usr) for i in range(int(num_card/10)): #移動到該元素(container)(即目前顯示的資訊)的底部(false) chrome.execute_script("arguments[0].scrollIntoView(false);",container) #在終端機上顯示,以便確定網頁有在,依所要的指示操作 print(i,": ","move to the bottom of container") #滾輪下滑1000 #因為移至「目前已顯示資訊的最底部」還不夠,還要再用滾輪往下滑一段距離,才會加載出一批新的資訊 chrome.execute_script("window.scrollBy(0,1000)") print("ok") #留時間給網頁載入(迴圈的) time.sleep(1) time.sleep(1) ############################inf_all#################################### data = chrome.page_source inf_all = get_inf_all_8(data) titles = ["銀行","信用卡","首刷哩程回饋","國外哩程回饋","國內哩程回饋"] inf_all[0][1] = "亞洲萬里通聯名鈦商卡" inf_all[1][1] = "亞洲萬里通聯名世界卡" inf_all[2][1] = "亞洲萬里通聯名白金卡" inf_all[8][1] = "亞洲萬里通聯名里享卡" print(titles) print(inf_all) chrome.close() return inf_all
def crash5(): print("網購") usr = '******' options = Options() options.add_argument("--disable-notifications") chrome = webdriver.Chrome( 'C:/Users/USER/OneDrive/桌面/信用卡推薦系統_爬蟲程式/chromedriver.exe', chrome_options=options) chrome.get(usr) #利用class_name 來定位所要抓取的部分 #在該網頁中,results-list-view,是放置所有信用卡資訊的 div 的 class name container = chrome.find_element_by_class_name("results-list-view") num_card = get_num_of_card(usr) for i in range(int(num_card / 10)): #移動到該元素(container)(即目前顯示的資訊)的底部(false) chrome.execute_script("arguments[0].scrollIntoView(false);", container) #在終端機上顯示,以便確定網頁有在,依所要的指示操作 print(i, ": ", "move to the bottom of container") #滾輪下滑1000 #因為移至「目前已顯示資訊的最底部」還不夠,還要再用滾輪往下滑一段距離,才會加載出一批新的資訊 chrome.execute_script("window.scrollBy(0,1000)") print("ok") #留時間給網頁載入(迴圈的) time.sleep(1) time.sleep(1) ############################inf_all#################################### data = chrome.page_source inf_all = get_inf_all_5(data) titles = ["銀行", "信用卡", "數位通路回饋上限", "國內消費現金回饋", "網購回饋"] print(titles) print(inf_all) chrome.close() return inf_all
def crash4(): print("分期零利率優惠") usr = '******' options = Options() options.add_argument("--disable-notifications") chrome = webdriver.Chrome('D:\\coding_project\\project\\credit_card_analize_project\\Server\\updateData\\chromedriver.exe', chrome_options=options) chrome.get(usr) #利用class_name 來定位所要抓取的部分 #在該網頁中,results-list-view,是放置所有信用卡資訊的 div 的 class name container = chrome.find_element_by_class_name("results-list-view") num_card = get_num_of_card(usr) for i in range(int(num_card/10)): #移動到該元素(container)(即目前顯示的資訊)的底部(false) chrome.execute_script("arguments[0].scrollIntoView(false);",container) #在終端機上顯示,以便確定網頁有在,依所要的指示操作 print(i,": ","move to the bottom of container") #滾輪下滑1000 #因為移至「目前已顯示資訊的最底部」還不夠,還要再用滾輪往下滑一段距離,才會加載出一批新的資訊 chrome.execute_script("window.scrollBy(0,1000)") print("ok") #留時間給網頁載入(迴圈的) time.sleep(1) time.sleep(1) ############################inf_all#################################### data = chrome.page_source inf_all = get_inf_all_4(data) titles = ["銀行","信用卡","年費","最高分期期數","最低分期金額限制"] print(titles) print(inf_all) chrome.close() return inf_all
def crash10(): print("紅利點數") usr = '******' options = Options() options.add_argument("--disable-notifications") chrome = webdriver.Chrome(path, chrome_options=options) chrome.get(usr) #利用class_name 來定位所要抓取的部分 #在該網頁中,results-list-view,是放置所有信用卡資訊的 div 的 class name container = chrome.find_element_by_class_name("results-list-view") num_card = get_num_of_card(usr) for i in range(int(num_card / 10)): #移動到該元素(container)(即目前顯示的資訊)的底部(false) chrome.execute_script("arguments[0].scrollIntoView(false);", container) #在終端機上顯示,以便確定網頁有在,依所要的指示操作 print(i, ": ", "move to the bottom of container") #滾輪下滑1000 #因為移至「目前已顯示資訊的最底部」還不夠,還要再用滾輪往下滑一段距離,才會加載出一批新的資訊 chrome.execute_script("window.scrollBy(0,1000)") print("ok") #留時間給網頁載入(迴圈的) time.sleep(1) time.sleep(1) ############################inf_all#################################### data = chrome.page_source inf_all = get_inf_all_10(data) titles = ["銀行", "信用卡", "紅利折抵金", "紅利換哩程", "最高基點倍數"] print(titles) print(inf_all) chrome.close() return inf_all
card_image_temp.pop(0) for i in range(4): card_image_temp.pop(-1) print(card_image_temp) print("ok") write_to_excel_1(card_image_temp, str(file_name), 'card_url', mode=0, ind=card_name) usr1 = 'https://www.money101.com.tw/%E4%BF%A1%E7%94%A8%E5%8D%A1/%E7%8F%BE%E9%87%91%E5%9B%9E%E9%A5%8B' N1 = get_num_of_card(usr1) + 20 folder_path1 = './image/1/' get_image_url(usr1, N1, folder_path1, 'card_usl_1.xlsx') usr2 = 'https://www.money101.com.tw/%E4%BF%A1%E7%94%A8%E5%8D%A1/%E5%93%A9%E7%A8%8B%E5%9B%9E%E9%A5%8B%E5%84%AA%E6%83%A0' N2 = get_num_of_card(usr2) + 20 folder_path2 = './image/2/' get_image_url(usr2, N2, folder_path2, 'card_usl_2.xlsx') usr3 = 'https://www.money101.com.tw/%E4%BF%A1%E7%94%A8%E5%8D%A1/%E5%8A%A0%E6%B2%B9%E5%8D%A1%E5%84%AA%E6%83%A0' N3 = get_num_of_card(usr3) + 20 folder_path3 = './image/3/' get_image_url(usr3, N3, folder_path3, 'card_usl_3.xlsx') usr4 = 'https://www.money101.com.tw/%E4%BF%A1%E7%94%A8%E5%8D%A1/%E9%9B%BB%E5%BD%B1%E5%84%AA%E6%83%A0' N4 = get_num_of_card(usr4) + 20