testing_tmp.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from sys import platform
  2. import time
  3. # from sys import platform
  4. #!/usr/bin/python
  5. # -*- coding: utf8 -*-
  6. import sys,os
  7. sys.path.append('../pygologin')
  8. from selenium import webdriver
  9. from selenium.webdriver.chrome.options import Options
  10. from pygologin.gologin import GoLogin
  11. from selenium.webdriver.common.by import By
  12. from selenium.webdriver.support.ui import WebDriverWait
  13. from selenium.webdriver.support import expected_conditions as EC
  14. from selenium.common.exceptions import NoSuchElementException
  15. from selenium.common.exceptions import StaleElementReferenceException
  16. import json
  17. from underthesea import ner
  18. from bs4 import BeautifulSoup
  19. import requests
  20. from datetime import datetime
  21. from datetime import timedelta
  22. TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2MzZiNjdiNTVhMTI5NzNmY2FiMzdlMTAiLCJ0eXBlIjoiZGV2Iiwiand0aWQiOiI2MzZiNjgwNDczY2QwZDFiNjNmYmM5YTIifQ.VfF22lLEMP3JSklvuWTgOfkxEKKHCcsSYQotg6zMcac"
  23. gl = GoLogin({
  24. "token": TOKEN,
  25. 'profile_id': "636b67b55a12973346b37e12",
  26. })
  27. proxy_list=[]
  28. for line in open("proxylist.txt","r"):
  29. line=line[:-1]
  30. proxy_list.append(line.split(":"))
  31. proxy_check=[]
  32. chrome_driver_path = "/Users/nguyenductai/Downloads/chromedriver"
  33. debugger_address = gl.start()
  34. chrome_options = Options()
  35. chrome_options.add_experimental_option("debuggerAddress", debugger_address)
  36. driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)
  37. driver.close()
  38. def creat_new_profile_id(gl, i):
  39. host=proxy_list[i][0]
  40. port=proxy_list[i][1]
  41. profile_id = gl.create({
  42. "name": 'profile_'+str(i),
  43. "os": 'mac',
  44. "proxyEnabled": True,
  45. "navigator": {
  46. "language": 'en-US,en;q=0.9,he;q=0.8',
  47. "userAgent": 'MyUserAgent',
  48. "resolution": '1024x768',
  49. "platform": 'darwin',
  50. },
  51. "proxy":{
  52. 'mode': 'socks5',
  53. 'host': host,
  54. 'port': port,
  55. 'username': "prateep6793",
  56. 'password': "Zing1234",
  57. }
  58. });
  59. return profile_id
  60. def clear_proxy_list(gl,driver):
  61. for i in range(len(proxy_list)-1):
  62. print(i)
  63. try:
  64. profile_id=creat_new_profile_id(gl,i)
  65. gl = GoLogin({
  66. "token": TOKEN,
  67. 'profile_id': profile_id,
  68. })
  69. chrome_driver_path = "/Users/nguyenductai/Downloads/chromedriver"
  70. debugger_address = gl.start()
  71. chrome_options = Options()
  72. chrome_options.add_experimental_option("debuggerAddress", debugger_address)
  73. driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)
  74. proxy_check.append(True)
  75. driver.get("https://www.google.com/")
  76. print("Okay")
  77. except:
  78. print("Error Proxy!")
  79. proxy_check.append(False)
  80. time.sleep(2)
  81. driver.refresh()
  82. driver.close()
  83. gl.delete(profile_id)
  84. clear_proxy_list(gl,driver)
  85. print(proxy_list)