【发布时间】:2020-11-30 20:43:51
【问题描述】:
我正在尝试通过网络抓取 youtube 评论部分。但在此之前,我想按 new 对 cmets 进行排序。所以我必须点击 SORT BY 然后 Newest First。但不幸的是,我没有运气。感谢您的帮助。
屏幕记录:https://imgur.com/Rt8gnIB
代码:
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:\Users\caspe\OneDrive\Documents\Övrigt\Kodning\Email\chromeDriver\chromedriver.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)
【问题讨论】:
-
...必须点击 SORT BY,然后点击 Newest First...,在哪一行没有运气?
-
不幸的是两者
-
我尝试同时使用 XPath 和完整 XPath,但在站点上找不到元素。 (最后两行)
标签: python python-3.x selenium selenium-webdriver pyautogui