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("--user-data-dir=C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 7\\")
-
- driver = webdriver.Chrome(options=options)
- driver.set_window_size(1400,1000)
- driver.get('https://twitter.com/hashtag/covid19?f=live')
- time.sleep(9999)
- time.sleep(3)
- scrolling(10)
- 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()
- time.sleep(9999)
- driver.quit()
|