अजगर सेलेनियम हेडलेस क्रोम [डुप्लिकेट]

Dec 11 2020

Im काम करने के लिए सिर रहित क्रोम प्राप्त करने की कोशिश कर रहा है और मैं सिर्फ काम करने के लिए नहीं कर सकता मैंने एक परीक्षण फ़ाइल बनाई जो काम करती है:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--headless")

driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe" , chrome_options=options)
driver.get('http://www.google.com')
print(driver.title)

यह काम करता है लेकिन एक त्रुटि भी पैदा करता है:

C:/Users/kgood/PycharmProjects/pythonProject1/Unknown.py:6: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe" , chrome_options=options)

मैं उस त्रुटि के साथ रह सकता हूं जो मुझे लगता है क्योंकि यह बिना शीर्षक के खुलता है, क्रोम को प्राप्त होता है, जैसे मैंने पूछा, शीर्षक को प्रिंट करता है, लेकिन जब मैं इसे अपने मुख्य प्रोजेक्ट में पेस्ट करने जाता हूं, तो यह अभी भी एक विंडो खोलता है, विंडो रिक्त है, और यह बस वहाँ एक खाली खिड़की के रूप में बैठता है जब तक कि यह समाप्त न हो जाए। किसी भी विचार क्या हो रहा है? यहाँ मेरे प्रोजेक्ट कोड की शुरुआत है:

from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
options = webdriver.ChromeOptions()
options.add_argument("--headless")

# gets the website
driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe" , chrome_options=options)
driver.get("https://www.legacyhomesal.com/pennington-freedom-series-richmond-ii")

# finds the Base Price header
price = driver.find_element_by_xpath("//h3[@class='ng-binding']")
print(price.text)

# converts the string to integer
p = price.text[12::]
r = int(p.replace(',', ''))
driver.close()

मैंने इसे करने के कई अलग-अलग तरीकों की कोशिश की है लेकिन केवल एक ही ऊपर, थोड़े काम करता है:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')  # Last I checked this was necessary.
driver = webdriver.Chrome(CHROMEDRIVER_PATH, chrome_options=options)

तथा

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.headless = True
driver = webdriver.Chrome(CHROMEDRIVER_PATH, chrome_options=options)

जवाब

2 PDHide Dec 11 2020 at 09:54
driver = webdriver.Chrome(options=options)

त्रुटि सही ढंग से कहती है कि इसका क्या अर्थ है, की options = your_optionतुलना में उपयोग करेंchrome_options = your_option

1 dachil1pil1 Dec 11 2020 at 11:34

सबसे अधिक संभावना है कि एक खाली खिड़की है क्योंकि आप दो बार "ड्राइवर" कह रहे हैं लेकिन पहले वाले के पास कोई यूआरएल नहीं है इसलिए यह सिर्फ खाली है। मैं पहले चालक चर से छुटकारा मिल जाएगा।