123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- from selenium import webdriver
- from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
- import time
- import os
- import urllib.parse
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.common.by import By
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.support import expected_conditions as EC
- import codecs
- import random
- from bs4 import BeautifulSoup
- import requests
- import time
- import rpyc
- import sys
- import docker
- def scrolling(pgnum):
- global driver
- ub = driver.find_element_by_css_selector('body')
- for i in range(pgnum):
- ub.send_keys(Keys.PAGE_DOWN)
- if pgnum>1:
- time.sleep(0.5)
- headers = {
- "Authorization": "Bearer " + "t35vhZtWNgvDNWHc3DJh0OKll3mcB9GvC8K2EAkBug2",
- "Content-Type": "application/x-www-form-urlencoded"
- }
- options = webdriver.ChromeOptions()
- #options.add_argument("--proxy-server=socks5://172.104.67.159:8180")
- #option.add_argument("--user-data-dir="+self.userdir+profilepath+"\\")
- options.add_argument("--user-data-dir=C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 7\\")
- #driver = webdriver.Remote(
- # command_executor='http://127.0.0.1:4444/wd/hub',
- #command_executor='http://192.53.174.202:4444/wd/hub',
- #command_executor='http://172.104.93.163:4444/wd/hub',
-
- #command_executor='http://dev2.choozmo.com:14444/wd/hub',
- #desired_capabilities=options.to_capabilities())
- driver = webdriver.Chrome(options=options)
- #desired_capabilities=DesiredCapabilities.CHROME)
- driver.set_window_size(1400,1000)
- #driver.get('https://twitter.com/hashtag/ContentMarketing?src=hashtag_click&f=user')
- #driver.get('https://twitter.com/hashtag/ContentMarketing?f=live')
- #driver.get('https://twitter.com/hashtag/socialmediamarketing?f=live')
- #driver.get('https://twitter.com/hashtag/startupbusinessideas?f=live')
- #driver.get('https://twitter.com/hashtag/taipei?f=live')
- #driver.get('https://twitter.com/hashtag/virtualhuman?f=live')
- #driver.get('https://twitter.com/hashtag/seo?f=live')
- #driver.get('https://twitter.com/hashtag/startup?f=live')
- #driver.get('https://twitter.com/hashtag/ai?f=live')
- #driver.get('https://twitter.com/hashtag/infographic?f=live')
- #driver.get('https://twitter.com/hashtag/MarTech?f=live')
- #driver.get('https://twitter.com/hashtag/videomarketing?f=live')
- #driver.get('https://twitter.com/hashtag/GrowthHacking?f=live')
- #driver.get('https://twitter.com/hashtag/DataScience?f=live')
- #driver.get('https://twitter.com/hashtag/DigitalMarketing?f=live')
- #driver.get('https://twitter.com/hashtag/DigitalTransformation?f=live')
- driver.get('https://twitter.com/hashtag/covid19?f=live')
- time.sleep(9999)
- time.sleep(3)
- scrolling(10)
- #elmts=driver.find_elements_by_xpath("//span[contains(text(),'Follow')]")
- 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']/..")
- lst={}
- for elmt in elmts:
- print(elmt)
- print(elmt.tag_name)
- lst[elmt.get_attribute('href')]=1
- for k,v in lst.items():
- driver.get(k)
- time.sleep(5)
- elmt=driver.find_element_by_xpath("//span[contains(text(),'Follow')]")
- webdriver.ActionChains(driver).move_to_element(elmt).perform()
- webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
- # i=random.randint(0,5)
- # if i <=2:
- # webdriver.ActionChains(driver).move_to_element(elmt).perform()
- # webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
- # time.sleep(3)
- time.sleep(9999)
- driver.quit()
- #time.sleep(9999)
|