browser_common.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from selenium import webdriver
  2. import time
  3. #import networkx as nx
  4. #import dataset
  5. #import pickle
  6. #import codecs
  7. from selenium.webdriver.common.keys import Keys
  8. import sys
  9. import os
  10. import time
  11. import re
  12. class JBrowser:
  13. def __init__(self):
  14. if os.name=='nt':
  15. os.chdir("C:\\Program Files\\Google\\Chrome\\Application\\")
  16. def set_profile_path(self,profilepath):
  17. self.profilepath=profilepath
  18. option = webdriver.ChromeOptions()
  19. option.add_argument('--disable-web-security')
  20. option.add_argument('--allow-running-insecure-content')
  21. if os.name=='nt':
  22. option.add_argument("--user-data-dir='C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data\\"+self.profilepath+"\\'")
  23. else:
  24. option.add_argument("--user-data-dir="+self.profilepath)
  25. option.add_argument('--profile-directory="Profile 1"')
  26. self.option=option
  27. driver = webdriver.Chrome(options=option)
  28. self.driver=driver
  29. # executor_url = driver.command_executor._url
  30. # session_id = driver.session_id
  31. def scrolling(self,pgnum):
  32. ub = self.driver.find_element_by_css_selector('body')
  33. for i in range(pgnum):
  34. ub.send_keys(Keys.PAGE_DOWN)
  35. if pgnum>1:
  36. time.sleep(0.5)
  37. def get(self,url):
  38. self.driver.get(url)
  39. def get_driver(self):
  40. return self.driver