Wednesday, October 17, 2018

Python - Open a new Tab instead of new Window with Selenium with Firefox in Python

Pretty crazy to work with multi-tab in Firefox with Selenium and here is some tips...
  1. locate webdriver_prefs.json under \\python_path\Lib\site-packages\selenium\
  2. set "browser.link.open_newwindow" from 2 to 3
  3. save before exit.
In program code, I did try using send_keys(Keys.CONTROL + 't') but it didn't succeed.
from selenium.webdriver.common.keys import Keys
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
You have to use javascript to call a new 'window'(tab) and then switch the current 'window'(tab) to newly created 'window'(tab)
driver.execute_script("window.open()")
driver.switch_to.window(driver.window_handles[-1])
After all the operation, you can close the newly created 'windows'(tab)
driver.close()
Remember, once you close the current 'window'(tab), you have to switch the 'window'(tab) back to first one(or another one) to access 'driver' or you will get an error saying the content has been dropped.
driver.switch_to.window(driver.window_handles[0])
A note for myself and for whom it may be interested in

Tuesday, October 16, 2018

發噏瘋 - 牛一

老撚套,我唔明公司點解要將人o既 private information 公佈出嚟?

你話係十月之星咪算喇,點解要公開 exactly 個日期先?有無問過我想唔想公開我私人資料?

Thursday, October 11, 2018

Python - 學會了 data scraping

Data Scraping 意思指從網路上獲取數據,而我o既玩法差唔多係等如 WYSIWYG。

本來要用 browser 逐條 link click 入去先睇到,家陣原來啲 programming 好很方便,有齊晒 module 俾你 remote control 一個 browser 去瀏覽網站,繼而透過獲取返嚟o既 HTML 再做分析,只抽取有用的部分為己用。而當中有一個叫 Selenium o既 package,佢可以好有效咁抽取 HTML 中的某啲 element(s),咁喺個 program 入邊做咩都得喇。

最過癮o既地方係,佢可以模擬返你瀏覽o既動作去 click,入 username 或者 password,針對動態改變o既內容網站就得心應手。如果只針對靜態網站,我估用 beautifulsoup 可能會仲快手啲。

我o既用途除咗想 scrap 吓 craigslist 之外,仲想 download 翻報紙啲文章留為己用。

真係比我整到個小 program 喎,好過癮。

Wednesday, October 03, 2018

轉台不似預期之陰魂不散

話說小弟兩個月前,即八月,由 Google Fi 轉台去 Walmart o既 FamilyMobile。以為大功告成,點知,佢原來八月轉台嗰時收咗我兩次錢。

第一次 charge 係由我 online 做 activation+transfer number 所引起的,但由於當時久久不能成功轉台,故我打去 CS 問佢搞咩兼再做一次轉台,咁佢就再 charge 多我一次月費,原來以為佢會自動取消第一次o既收費,或者順延一個月才 renew 個 prepiad plan,好顯然係我諗多咗喇。咁我咪又再一次打去 service hotline 去追討多 charge 的費用。由於我啲英文好水皮,第一時間就想同 CS 玩 chatbox 去搞 refund,可惜,逢係關於帳單,錢銀嘅都要你打去 CS hotline 度處理。好喇我硬住頭皮打去 CS。除咗我英文屎,仲有就係我肯定佢啲 CS 係印度人接聽,因為 FamilyMobile 啲 CS service 已經外判咗俾 Tracfone,出名地差。。。

好喇,第一次打去,佢話 check 唔到有 double charge 喎,叫我去 bank/credit card 度處理。。。唉,我 system 都睇到俾咗兩次錢,點會無 double charged 呢?但係佢死都唔同我處理,淨係識得叫我 contact bank…無功而還。

食完晚飯,心有不甘,再打去 CS 度問。咦,呢次呢個 CS 好好喎,佢都話見到同一個 number 同一金額 charge 咗兩次,佢都同意係收多咗錢,可以 refund。個心即時鬆一口氣,等佢個 system load 啲資料出嚟等到天荒地老。。。最後對埋個 credit card 最尾 4 個數字,就話 ok,等 3 至 5 business days 就會過數,咁我滿心歡喜咁等喇。

點知,等下一日,等下又一日,等咗成個幾禮拜都唔見到 refund 嘅?

如是者我又硬住頭皮咁又打多次去 CS hotline,又重覆一之成個 case 俾佢聽,呢2佢又一樣好順利喎,又係話見到同一 service number 同一金額 charge 咗兩次,同意 refund。又係同 credit card 尾 4 位 number,加一陣佢 load system 嘅時間,3就話 ok 啦,又係 3 到 5 business day 先會過數,呢次仲俾埋 transcation number 我添,我亦問佢有個 case number 等我有喵問題可以 reference 或者 follow,佢就話無開 case number,因為都做咗 refund, problem solved,所以無 case number。佢話有問題就再打去 hotline,有 record 喎。好啦,無奈地停多佢一次喇。

今日,我終於係 myfamilymobile.com 見到個 refund record,同時間,credit card 都終於出現咗個 $56.xx 嘅 credit。

睇嚟,我又可以準備搵 plan 轉了。