ltest.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from selenium import webdriver
  2. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  3. import time
  4. import os
  5. import urllib.parse
  6. from selenium.webdriver.support.ui import WebDriverWait
  7. from selenium.webdriver.common.by import By
  8. from selenium.webdriver.support import expected_conditions as EC
  9. import codecs
  10. import random
  11. from bs4 import BeautifulSoup
  12. import requests
  13. import time
  14. import rpyc
  15. import sys
  16. import docker
  17. headers = {
  18. "Authorization": "Bearer " + "t35vhZtWNgvDNWHc3DJh0OKll3mcB9GvC8K2EAkBug2",
  19. "Content-Type": "application/x-www-form-urlencoded"
  20. }
  21. options = webdriver.ChromeOptions()
  22. #options.add_argument("--proxy-server=socks5://172.104.67.159:8180")
  23. #option.add_argument("--user-data-dir="+self.userdir+profilepath+"\\")
  24. options.add_argument("--user-data-dir=C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 7\\")
  25. #driver = webdriver.Remote(
  26. # command_executor='http://127.0.0.1:4444/wd/hub',
  27. #command_executor='http://192.53.174.202:4444/wd/hub',
  28. #command_executor='http://172.104.93.163:4444/wd/hub',
  29. #command_executor='http://dev2.choozmo.com:14444/wd/hub',
  30. #desired_capabilities=options.to_capabilities())
  31. driver = webdriver.Chrome(options=options)
  32. #desired_capabilities=DesiredCapabilities.CHROME)
  33. driver.set_window_size(1400,1000)
  34. driver.get('https://www.linkedin.com/mynetwork/')
  35. time.sleep(5)
  36. elmts=driver.find_elements_by_xpath("//ul[@class='artdeco-card mb4 overflow-hidden']//button[contains(@aria-label,'邀請')]")
  37. #elmts=driver.find_elements_by_xpath("//ul[@class='artdeco-card mb4 overflow-hidden']//span[@class='artdeco-button__text']/..//button[contains(@aria-label,'邀請')")
  38. #elmts=driver.find_elements_by_xpath("//span[contains(text(),'建立關係')]/..")
  39. for elmt in elmts:
  40. print(elmt)
  41. i=random.randint(0,5)
  42. if i <=2:
  43. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  44. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  45. time.sleep(3)
  46. print(elmts)
  47. print(len(elmts))
  48. time.sleep(9999)
  49. #https://whatismyipaddress.com/ip/61.230.75.30
  50. #driver.get('https://whatismyipaddress.com/')
  51. #fw=codecs.open('c:/tmp/gg.html','w','utf-8')
  52. #fw.write(driver.page_source)
  53. #fw.close()
  54. #import sys
  55. #sys.exit()