Using Selenium without using any browser

北城以北 提交于 2021-02-17 05:07:44

问题


I have been trying to do web automation using selenium,Is there any way to use browser like chrome,firefox without actually installing then, like using some alternate options, or having portable versions of them.If I can use portable versions how do i tell selenium to use it?


回答1:


To use the browsers like google-chrome and firefox you have to install the full-blown browser.

You can find a detailed discussion in Is Chrome installation needed or only chromedriver when using Selenium?


As an alternative you can use the headless phantomjs browser as follows:

  • Code Block:

    from selenium import webdriver
    
    driver = webdriver.PhantomJS(executable_path=r'C:\WebDrivers\phantomjs.exe', service_args=['--ignore-ssl-errors=true', '--ssl-protocol=tslv1.0'])
    driver.set_window_size(1920, 1080)
    driver.get("https://account.booking.com/register?op_token=EgVvYXV0aCJ7ChQ2Wjcyb0hPZDM2Tm43emszcGlyaBIJYXV0aG9yaXplGhpodHRwczovL2FkbWluLmJvb2tpbmcuY29tLyo2eyJwYWdlIjoiL3JlZGlyZWN0LXRvLWpvaW5hcHAtbHA_bGFuZz1pdCZhaWQ9MTE4NzM2MCJ9QgRjb2RlKg4QAToAQgBY5dGK8gVgAQ")
    print(driver.page_source)
    driver.quit()
    

You can find a detailed discussion in PhantomJS can't load correctly web page


References

A couple of relevent discussions:

  • Do headless web browser need selenium WebDriver?
  • Difference of Headless browsers for automation



回答2:


If you install pip install selenium

it comes with the protable chrome browser, no need to install any browser for this.

the chrome has a tag "chrome is controlled by automated test software" near search bar



来源:https://stackoverflow.com/questions/62442465/using-selenium-without-using-any-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!