selenium - Manage one Python project for different platform? -
i have python project, hope run both mac osx , raspbian(raspberry pi).
in case, want know how can manage project(whole scripts) both platform?
i know codes platform-independent, codes, selenium, platform dependent. why?
the reason :
my program crawling web page , collecting data headlessly.
i use raspberry ssh , command line interface available.
i use phantomjs on max osx. phantomjs difficult , complex install in raspberry pi.
so, have use different webdriver
both cases.
in mac osx,
browser = webdriver.phantomjs()
in raspbian,
from pyvirtualdisplay import display display = display(visible=0, size=(800, 600)) display.start() self.browser = webdriver.firefox()
but managing 2 discrete python projects (one mac osx, other raspbian) kinda irratating..
if insert codes below deal it,
import platform if platform.system() == 'linux': pyvirtualdisplay import display display = display(visible=0, size=(800, 600)) display.start() self.browser = webdriver.firefox() elif platform.system() =='darwin': # mac osx browser = webdriver.phantomjs()
everytime code changed, have transfer whole project file raspberry pi, irritating.
how deal effectively?
you can divide code several files: 1. rasp.py
def raspberry_run(): pyvirtualdisplay import display display = display(visible=0, size=(800, 600)) display.start() self.browser = webdriver.firefox()
mac.py
def mac_run():
browser = webdriver.phantomjs()
main.py
import platform
from mac import *
from rasp import *
if platform.system() == 'linux':
raspberry_run()
elif platform.system() =='darwin':
mac_run()
every time change mac.py or raps.py, don't need change main.py.
Comments
Post a Comment