我已经完全按照更改进行操作,但它不起作用,是否还有其他错误?
https://www.selenium.dev/blog/2023/headless-is-going-away/
import time
import pandas as pd
from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
options = webdriver.ChromeOptions()
options.headless = True
options.page_load_strategy = 'none'
chrome_path = 'chromedriver.exe'
chrome_service = Service(chrome_path)
driver = Chrome(options=options, service=chrome_service)
driver.implicitly_wait(5)
url= "https://hk.centanet.com/findproperty/list/transaction/%E6%84%89%E6%99%AF%E6%96%B0%E5%9F%8E_3- DMHSZHHRHD?q=TiDxvVGMUUeutVzA0g1JlQ"
driver.get(url)
time.sleep(10)
contents = driver.find_element(By.CSS_SELECTOR,"div[class*='bx--structured-list-tbody']")
properties = contents.find_elements(By.CSS_SELECTOR,"div[class*='bx--structured-list-row']")
def extract_data(element):
columns = element.find_elements(By.CSS_SELECTOR,"div[class*='bx--structured-list-td']")
Date = columns[0].text
Dev = columns[1].text
Price = columns[3].text
RiseBox = columns[4].text
Area = columns[5].text
return{
"Date": Date,
"Development": Dev,
"Consideration": Price,
"Change": RiseBox,
"Area": Area
}
data = []
for property in properties:
extracted_data = extract_data(property)
data.append(extracted_data)
df = pd.DataFrame(data)
df.to_csv("result.csv", index=False)
评论如下:
Selenium.py:10: DeprecationWarning: headless property is deprecated, instead use add_argument('--headless') or add_argument('--headless=new')
options.headless = True
我尝试了建议的更改https://www.selenium.dev/blog/2023/headless-is-going-away/但这不起作用
This warning信息...
DeprecationWarning: headless property is deprecated, instead use add_argument('--headless') or add_argument('--headless=new') options.headless = True
...与Selenium带有标题的博客文章无头者即将消失!
Details
Chromium 团队发布了 Native Headless 模式,现在正式成为新无头模式。此功能可用于:
- 铬 v109.0.5400.0
- ChromeDriver v109.0.5414.25
- 硒 v4.8.0
新语法要求--headless=new
作为参数传递,如下所示:
-
Java:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");
WebDriver driver = new ChromeDriver(options);
driver.get("https://selenium.dev);
driver.quit();
-
Python:
options = ChromeOptions()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
driver.get('http://selenium.dev')
driver.quit()
-
JavaScript:
let driver = await env
.builder()
.setChromeOptions(options.addArguments('--headless=new'))
.build();
await driver.get('https://selenium.dev');
await driver.quit();
-
CSharp:
var options = new ChromeOptions();
options.AddArgument("--headless=new");
var driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://selenium.dev");
driver.Quit();
-
Ruby:
options = Selenium::WebDriver::Options.chrome(args: ['--headless=new'])
driver = Selenium::WebDriver.for :chrome, options: options
driver.get('https://selenium.dev')
driver.quit
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)