我正在尝试编写代码来访问 Aliexpress 并搜索商品,然后提取详细信息,例如产品名称、价格等;逐页复制到 Excel 文档。我寻求通过此处发布的先前问题来构建它。多亏了这一点。
不知何故,我能够在前 5 或 6 次测试运行中搜索该项目,但突然间,Aliexpress 要求我登录或注册。
1.) 第一个问题,为什么任何浏览器不注册就无法访问网站?他们认出了我的用户代理吗?
2.) 其次,我写了一个自动登录的代码。网站包含很多 Javascript,它是一个响应式网站。当我们单击它们时,会出现一些 html 元素。在自动登录时,我的代码不会检测到页面的电子邮件或密码元素。有什么东西阻止它被检测到吗?我该如何解决这个问题?
我在这里放了我的示例代码:
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
//To input the user's search
Scanner nw1 = new Scanner(System.in);
System.out.println("What do you want to search?");
String a = nw1.nextLine();
//Open the driver
System.setProperty("webdriver.chrome.driver",
"E:\\JetBrains\\webdriver\\chrome\\chromedriver.exe");
WebDriver AE = new ChromeDriver();
//Open the web page and Login in.
AE.get("https://www.aliexpress.com/");
Thread.sleep(2000);
//xpath of account button
AE.findElement(By.xpath("//*[@id="nav-user-account"]/div/div/p[3]/a[2]")).click();
//xpath of Sign in button
AE.findElement(By.xpath("/html/body/div[9]/a")).click();
AE.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//xpath of Email box
AE.findElement(By.xpath("//*[@id=\"fm-login-id\"]")).sendKeys("my-email");
//xpath of password section to type
AE.findElement(By.xpath("//*[@id=\'fm-login-password\']")).sendKeys("my-password");
AE.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// xpath of submit button
AE.findElement(By.xpath("//*[@id="login-form"]/div[5]/button")).click()
对不起,我第一次来这里。欢迎任何有用的意见。谢谢。