简体   繁体   中英

Can I install chromedriver on python anywhere and not use it headless?

I am trying to use this code that works on my local machine on python anywhere and i want to understand if it is even possible:


from selenium import webdriver
from bs4 import BeautifulSoup
import time

# Initialize webdriver
driver = webdriver.Chrome(executable_path="/Users/matteo/Downloads/chromedriver")

# Navigate to website
driver.get("https://apnews.com/article/prince-harry-book-meghan-royals-4141be64bcd1521d1d5cf0f9b65e20b5")

time.sleep(5)
# Parse page source
soup = BeautifulSoup(driver.page_source, "html.parser")

# Find desired elements using Beautiful Soup
elements = soup.find_all("p")

# Print element text
for element in elements:
    print(element.text)

# Close webdriver
driver.quit()

Do i need to have installed chrome to make that work or is chromium enough? Because when i run that code on my local machine a chrome page opens up. How does that work on python anywhere? Would it crush?

I am wondering if the code i am using only works if someone is on a GUI with Chrome installed or if it can work on python anywhere too.

The short answer is no. ChromeDriver must have chrome installed. You can run your tests headless for time save, but chrome still must be installed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM