I'm trying to web scrape a youtube comment section. But before that, I want to sort the comments by new. So I have to click on the SORT BY and then Newest First. But unfortunately, I have no luck. Thank you for helping out.
Screen record: https://imgur.com/Rt8gnIB
code:
import sys, unittest, time, datetime
import urllib.request, urllib.error, urllib.parse
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import InvalidArgumentException
from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver import ActionChains
from bs4 import BeautifulSoup
import requests
import requests.exceptions
from urllib.parse import urlsplit
from collections import deque
import re
import os
import shutil
import smtplib
import string
import pyautogui
options = webdriver.ChromeOptions()
options.add_argument('--lang=en')
options.add_argument("--start-maximized")
driver = webdriver.Chrome(executable_path=r'C:UserscaspeOneDriveDocuments?vrigtKodningEmailchromeDriverchromedriver.exe', chrome_options=options)
driver.get("https://www.youtube.com/watch?v=EV6PLN_8RBw")
time.sleep(5)
screenWidth, screenHeight = pyautogui.size()
currentMouseX, currentMouseY = pyautogui.position()
pyautogui.moveTo(1050, 780) # Move the mouse to XY coordinates.
pyautogui.click()
print("clicked")
time.sleep(1)
pyautogui.moveTo(1250, 880) # Move the mouse to XY coordinates.
pyautogui.click()
print("clicked")
time.sleep(1)
pyautogui.moveTo(700, 500) # Move the mouse to XY coordinates.
pyautogui.click()
print("clicked")
time.sleep(1)
See Question&Answers more detail:os