英文:
Write a Java webdriver selenium script to increase number of views on youtube video not working
问题
我编写了一个Selenium脚本来增加我的YouTube视频的观看次数。当前的观看次数是:164,我想增加100次。以下是我的代码。问题在于,尽管网页被访问了100次,但似乎浏览器自动化没有增加计数,原因是什么?有什么解决方法吗?我想也许他们知道我是从同一个IP地址访问网站,也许更改IP地址可以解决这个问题?如果可以的话,怎么做?
package Test;
// Selenium IDE生成的代码
import org.junit.Before;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.After;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNot.not;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import java.util.*;
import java.net.MalformedURLException;
import java.net.URL;
public class YoutubeAutomation {
private static WebDriver driver;
private Map<String, Object> vars;
JavascriptExecutor js;
@BeforeEach
public void setUp() {
driver = new ChromeDriver();
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
@AfterAll
public static void tearDown() {
driver.quit();
}
public String waitForWindow(int timeout) {
try {
Thread.sleep(timeout);
} catch (InterruptedException e) {
e.printStackTrace();
}
Set<String> whNow = driver.getWindowHandles();
Set<String> whThen = (Set<String>) vars.get("window_handles");
if (whNow.size() > whThen.size()) {
whNow.removeAll(whThen);
}
return whNow.iterator().next();
}
@Test
public void test() throws InterruptedException {
String[] videosURLs = {"https://www.youtube.com/watch?v=sZ86JHQ9TCA&ab_channel=MounaCameliaHammoudi"};
// 可以添加更多视频URL
for(int i=0; i<100; i++) {
for( String videoURL: videosURLs) {
driver.get(videoURL);
System.out.println("MOUNA CAMELIA "+i+" "+videoURL);
}
}
}
}
这是您提供的代码的翻译。如果您有其他问题或需要进一步的帮助,请告诉我。
英文:
I wrote a Selenium script to increase the number of views of my youtube video. The current view count is: 164, I would like to increase this by 100. Here is my code below. The problem is that it seems that the browser automation does not increase the count even though the web page is accessed 100 times, what is the reason? Any fix? I was thinking maybe they know that I am accessing the website from the same IP address, maybe a change of IP address could fix this? If yes, how?
package Test;
// Generated by Selenium IDE
import org.junit.Before;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.After;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNot.not;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import java.util.*;
import java.net.MalformedURLException;
import java.net.URL;
public class YoutubeAutomation {
private static WebDriver driver;
private Map<String, Object> vars;
JavascriptExecutor js;
@BeforeEach
public void setUp() {
driver = new ChromeDriver();
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
@AfterAll
public static void tearDown() {
driver.quit();
}
public String waitForWindow(int timeout) {
try {
Thread.sleep(timeout);
} catch (InterruptedException e) {
e.printStackTrace();
}
Set<String> whNow = driver.getWindowHandles();
Set<String> whThen = (Set<String>) vars.get("window_handles");
if (whNow.size() > whThen.size()) {
whNow.removeAll(whThen);
}
return whNow.iterator().next();
}
@Test
public void test() throws InterruptedException {
String[] videosURLs = {"https://www.youtube.com/watch?v=sZ86JHQ9TCA&ab_channel=MounaCameliaHammoudi"
// , "https://www.youtube.com/watch?v=4nYbkKicMmA&ab_channel=MounaCameliaHammoudi",
// "https://www.youtube.com/watch?v=b2F8AoqdHTs&ab_channel=MounaCameliaHammoudi",
// "https://www.youtube.com/watch?v=sZ86JHQ9TCA&ab_channel=MounaCameliaHammoudi",
// "https://www.youtube.com/watch?v=yhK5r9uyBTo&t=508s&ab_channel=MounaCameliaHammoudi",
// "https://www.youtube.com/watch?v=wgWxpdx8UGM&ab_channel=MounaCameliaHammoudi",
// "https://www.youtube.com/watch?v=NC7Xq9CdBVk&ab_channel=MounaCameliaHammoudi",
// "https://www.youtube.com/watch?v=kdtn4RYgCYM&ab_channel=MounaCameliaHammoudi"
};
for(int i=0; i<100; i++) {
for( String videoURL: videosURLs) {
driver.get(videoURL);
System.out.println("MOUNA CAMELIA "+i+" "+videoURL);
}
}
}
}
答案1
得分: 1
我认为当观看时间未达到最低要求时,浏览次数不会计入,当然,一个IP地址不能用来增加您的观看次数,您应该经常更改它,并且要解决IP地址问题,您可以使用带有Selenium的VPN扩展,如果您想查看类似的操作,可以在该存储库中查看:Youtube_Watch_Bot
英文:
I think views does not count when minimum watching time is not reached & of cours one ip adresse will not work to increase your views, you should alway change it & for fix ip adresse problem you can use vpn extenion with selenium i do something similar in that repo if you want to see : Youtube_Watch_Bot
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论