是 PYTHON PACKAGE?還是FUNCTION?

有冇師傅知道下面個function 點用﹖
呢個係一個stop website infinite loading 既 function.
如果我有個 do loop, 係有一個LIST 去CHECK 十個WEBSITE, 但果幾個WEBSITE都有INFINITE LOADING 既情況, 想請教個DO LOOP 應該放係邊﹖

PYTHON 我係自學, 但係其實我唔係好知呢舊野係乜. 而我成日見有人會咁寫, 有冇師兄可以解釋下.
FUNCTION 我其實係有D明, 但呢舊野似係一個 外掛 PACKAGE 咁.
點引用又唔知...
THANKS.

from __future__ import print_function

from selenium import webdriver
from selenium.common.exceptions import TimeoutException

def get_page(driver, page):
    try:
        driver.get(page)
    except TimeoutException:
        pass


def main():

    driver = webdriver.Chrome()

    try:
        driver.set_page_load_timeout(5)
        get_page(driver, "http://your/long/url")

        print("Returned from page get")

        from pprint import pprint as pp
        pp(driver.page_source)

    finally:
        driver.quit()

if __name__ == "__main__":
    main()

本帖最後由 procapitalist 於 2017-9-13 12:33 編輯

係function來的。package唔會係同一個file入面


你infinite loading是不是指個網頁應該限時内把全部野(圖片,影片,文字)都load o西出來?

如果係,python好像沒有do loop (source:
https://stackoverflow.com/questi ... hile-loop-in-python)

python loop點用:https://www.learnpython.org/en/Loops


建議更正如下:

from __future__ import print_function what is this?

from selenium import webdriver
from selenium.common.exceptions import TimeoutException

def get_page(driver, page):
    try:
        driver.get(page)
        print("Returned from page get")

    except TimeoutException:
        pass


def main():

    driver = webdriver.Chrome()

    try:
        driver.set_page_load_timeout(5)
         websites = ["http://www.yahoo.com/", "http://www.hkepc.com/", "http://www.yourwebsite.com/", "http://www.yourwebsite2.com/", "http://www.yourwebsite3.com/"]
         for website in websites:
              get_page(driver, "http://your/long/url")



        from pprint import pprint as pp
        pp(driver.page_source)
what is this??

missing except block : https://docs.python.org/3/tutorial/errors.html

    finally:
        driver.quit()

if __name__ == "__main__":
    main()

TOP

P.S.我都玩過Selenium,不過係java玩過

TOP