【发布时间】:2018-07-15 12:02:21
【问题描述】:
我正在尝试执行无头 Chrome 文本抓取,但遇到了问题。每当我运行下面的代码时,我都会收到一条错误消息:
ChromeOptions 选项 = new ChromeOptions(); SyntaxError: 无效的语法。
关于如何解决这个问题的任何想法?非常感谢!
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
ChromeOptions options = new ChromeOptions();
options.addArguments("window-size=1400,800");
options.addArguments("headless");
WebDriver driver = new ChromeDriver(options);
driver.get('https://www.samplehomepage.com')
latest_comment = driver.find_element_by_css_selector('p')
print(latest_comment.text)
【问题讨论】:
-
我看到一些带有一些 Java 或 C# 的 python。你不能在同一个脚本中使用两种语言。