Thư viện webbrowser Python
The webbrowser module provides a high-level interface to allow displaying Web-based documents to users. Under most circumstances, simply calling the open() function from this module will open url using the default browser . You have to import the module and use open() function. exampleIf new is 0, the url is opened in the same browser window if possible. If new is 1, a new browser window is opened if possible. If new is 2, a new browser page ("tab") is opened if possible. A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Made this for a game I play, it was relevant so i'm leaving it. It's real simple. Grabs the value from platform.system. Checks it against known values for different operating systems. If it finds a match it sets the chrome path for you. If none are found it opens default browser to your link. Hope its useful to someone.
I actually changed it some more here it is updated since I am still working on this launcher [tintuc] Ví muốn mở các trang chuyên về dược hóa sau: google2.fda.gov www.ema.europa.eu kensaku.mhlw.go.jp www.canada.ca search.who.int search.health.gov.au mohfw.gov.in patents.google.com www.freepatentsonline.com search.tga.gov.au vinapharm.com.vn www.google.com.vn congbomypham.cqldvn.gov.vn www.pharmacompass.com api-generic.com mail.google.com www.cochrane.org clinicaltrials.gov archive.org eurekasante.vidal.fr www.sciencedirect.com www.ebi.ac.uk www.alibaba.com www.sciencedirect.com www.chemblink.com www.pharmtech.com Các bước tiến hành như sau: Bước 1: Lưu các trang web vào file text (dùng notepad hoặc các phần mềm tương tự lưu). Xem hình Lưu các urls vào file text Bước 2: Chuẩn bị Python Cài đặc chương trình Python tải từ trang web https://www.python.org/ về Cái đặt theo mặc định Tải Python Bước 3: Viết đoạn lệnh Python sau: import subprocess as sp import webbrowser import time f = open('duoc_my_pham.txt','r') urls = f.readlines() for url in urls: child = sp.Popen(["C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", url ]) time.sleep(30) child.kill() Lưu ý: 1. Tên "duoc_my_pham.txt" thay bằng tên file của mình tự đặt 2. Dùng trình duyệt tùy thích Ví dụ: Google chrome: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" Firefox: "C:\Program Files\Mozilla Firefox\firefox.exe" .... 3. Thời gian nhanh chậm khi mở một link bằng cách chỉnh số trong " time.sleep(30) " 4. Nếu không muốn nó tự đóng nên bỏ dòng " child.kill()" đi. Đoạn mã chạy Python Lưu đơạn mã trên thành file có phần mỡ rộng *.py Có thể tải file mã tại đây Cứ thế chương trình cứ chạy và mở các trang web mình cần xem Có thể chạy trên Linux Ubuntu bằng lệnh sau: Chạy trên Ubuntu import subprocess as sp import webbrowser import time f = open('BioMed.txt','r') urls = f.readlines() for url in urls: child = sp.Popen(["firefox", url ]) time.sleep(20) child.kill() Bạn có thắc mắc gửi mail về [email protected] hoặc [email protected] Chúc bạn thành công! [/tintuc] |