general_browser.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.common.keys import Keys
  9. from selenium.webdriver.support import expected_conditions as EC
  10. import codecs
  11. import random
  12. from bs4 import BeautifulSoup
  13. import requests
  14. import time
  15. import rpyc
  16. import sys
  17. import docker
  18. def scrolling(pgnum):
  19. global driver
  20. ub = driver.find_element_by_css_selector('body')
  21. for i in range(pgnum):
  22. ub.send_keys(Keys.PAGE_DOWN)
  23. if pgnum>1:
  24. time.sleep(0.5)
  25. headers = {
  26. "Authorization": "Bearer " + "t35vhZtWNgvDNWHc3DJh0OKll3mcB9GvC8K2EAkBug2",
  27. "Content-Type": "application/x-www-form-urlencoded"
  28. }
  29. options = webdriver.ChromeOptions()
  30. #options.add_argument("--proxy-server=socks5://172.104.67.159:8180")
  31. #option.add_argument("--user-data-dir="+self.userdir+profilepath+"\\")
  32. options.add_argument("--user-data-dir=C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 7\\")
  33. #driver = webdriver.Remote(
  34. # command_executor='http://127.0.0.1:4444/wd/hub',
  35. #command_executor='http://192.53.174.202:4444/wd/hub',
  36. #command_executor='http://172.104.93.163:4444/wd/hub',
  37. #command_executor='http://dev2.choozmo.com:14444/wd/hub',
  38. #desired_capabilities=options.to_capabilities())
  39. driver = webdriver.Chrome(options=options)
  40. #desired_capabilities=DesiredCapabilities.CHROME)
  41. driver.set_window_size(1400,1000)
  42. #driver.get('https://twitter.com/hashtag/ContentMarketing?src=hashtag_click&f=user')
  43. #driver.get('https://twitter.com/hashtag/ContentMarketing?f=live')
  44. #driver.get('https://twitter.com/hashtag/socialmediamarketing?f=live')
  45. #driver.get('https://twitter.com/hashtag/startupbusinessideas?f=live')
  46. #driver.get('https://twitter.com/hashtag/taipei?f=live')
  47. #driver.get('https://twitter.com/hashtag/virtualhuman?f=live')
  48. #driver.get('https://twitter.com/hashtag/seo?f=live')
  49. #driver.get('https://twitter.com/hashtag/startup?f=live')
  50. #driver.get('https://twitter.com/hashtag/ai?f=live')
  51. #driver.get('https://twitter.com/hashtag/infographic?f=live')
  52. #driver.get('https://twitter.com/hashtag/MarTech?f=live')
  53. #driver.get('https://twitter.com/hashtag/videomarketing?f=live')
  54. #driver.get('https://twitter.com/hashtag/GrowthHacking?f=live')
  55. #driver.get('https://twitter.com/hashtag/DataScience?f=live')
  56. #driver.get('https://twitter.com/hashtag/DigitalMarketing?f=live')
  57. #driver.get('https://twitter.com/hashtag/DigitalTransformation?f=live')
  58. driver.get('https://twitter.com/hashtag/covid19?f=live')
  59. time.sleep(9999)
  60. time.sleep(3)
  61. scrolling(10)
  62. #elmts=driver.find_elements_by_xpath("//span[contains(text(),'Follow')]")
  63. elmts=driver.find_elements_by_xpath("//div[@class='css-1dbjc4n r-1twgtwe r-sdzlij r-rs99b7 r-1p0dtai r-1mi75qu r-1d2f490 r-1ny4l3l r-u8s1d r-zchlnj r-ipm5af r-o7ynqc r-6416eg']/..")
  64. lst={}
  65. for elmt in elmts:
  66. print(elmt)
  67. print(elmt.tag_name)
  68. lst[elmt.get_attribute('href')]=1
  69. for k,v in lst.items():
  70. driver.get(k)
  71. time.sleep(5)
  72. elmt=driver.find_element_by_xpath("//span[contains(text(),'Follow')]")
  73. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  74. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  75. # i=random.randint(0,5)
  76. # if i <=2:
  77. # webdriver.ActionChains(driver).move_to_element(elmt).perform()
  78. # webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  79. # time.sleep(3)
  80. time.sleep(9999)
  81. driver.quit()
  82. #time.sleep(9999)