Your Name 4 years ago
parent
commit
a678427345
2 changed files with 19 additions and 7 deletions
  1. 7 0
      tests/seltest.py
  2. 12 7
      web/browser_common.py

+ 7 - 0
tests/seltest.py

@@ -0,0 +1,7 @@
+import sys
+sys.path.insert(0,'./kw_tools/web')
+import browser_common
+jb=browser_common.JBrowser()
+jb.set_profile_path('/home/jared/.config/google-chrome/Default/')
+jb.get('http://www.yahoo.com.tw')
+

+ 12 - 7
web/browser_common.py

@@ -1,9 +1,9 @@
 from selenium import webdriver
 import time
-import networkx as nx
-import dataset
-import pickle
-import codecs
+#import networkx as nx
+#import dataset
+#import pickle
+#import codecs
 from selenium.webdriver.common.keys import Keys
 import sys
 import os
@@ -12,15 +12,20 @@ import re
 
 class JBrowser:
     def __init__(self):
-        os.chdir("C:\\Program Files\\Google\\Chrome\\Application\\")
+        if os.name=='nt':
+            os.chdir("C:\\Program Files\\Google\\Chrome\\Application\\")
 
 
     def set_profile_path(self,profilepath):
         self.profilepath=profilepath
         option = webdriver.ChromeOptions()
         option.add_argument('--disable-web-security') 
-        option.add_argument('--allow-running-insecure-content') 
-        option.add_argument("--user-data-dir=C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data\\"+self.profilepath+"\\")
+        option.add_argument('--allow-running-insecure-content')
+        if os.name=='nt':
+            option.add_argument("--user-data-dir='C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data\\"+self.profilepath+"\\'")
+        else:
+            option.add_argument("--user-data-dir="+self.profilepath)
+
         self.option=option
         driver = webdriver.Chrome(options=option)
         self.driver=driver