browser_common.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. import json
  13. import configparser, os
  14. from os.path import expanduser
  15. class JBrowser:
  16. def __init__(self):
  17. os.chdir("C:\\Program Files\\Google\\Chrome\\Application\\")
  18. home = expanduser("~")
  19. print(home)
  20. config = configparser.ConfigParser()
  21. content=config.read_file(open(home+'\\test.cfg'))
  22. print(content)
  23. print(config['DEFAULT'])
  24. print(config.sections())
  25. self.userdir=config['DEFAULT'].get('userdir')
  26. def set_profile_path(self,profilepath):
  27. self.profilepath=profilepath
  28. option = webdriver.ChromeOptions()
  29. option.add_argument('--disable-web-security')
  30. option.add_argument('--allow-running-insecure-content')
  31. option.add_argument("--user-data-dir="+self.userdir+profilepath+"\\")
  32. # option.add_argument("--user-data-dir=C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data\\"+self.profilepath+"\\")
  33. self.option=option
  34. driver = webdriver.Chrome(options=option)
  35. self.driver=driver
  36. # executor_url = driver.command_executor._url
  37. # session_id = driver.session_id
  38. def scrolling(self,pgnum):
  39. ub = self.driver.find_element_by_css_selector('body')
  40. for i in range(pgnum):
  41. ub.send_keys(Keys.PAGE_DOWN)
  42. if pgnum>1:
  43. time.sleep(0.5)
  44. def get(self,url):
  45. self.driver.get(url)
  46. def get_driver(self):
  47. return self.driver
  48. #jb=JBrowser()
  49. #jb.set_profile_path("Profile 7")
  50. #jb.get('https://m.facebook.com/ufi/reaction/profile/browser/?ft_ent_identifier=1981894498624379&ref=page_internal')
  51. #time.sleep(3)