Python问题,机械化机器人

2024-03-29 05:02:07 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
1条回答
网友
1楼 · 发布于 2024-03-29 05:02:07

下面是使用Selenium和隐藏浏览器的代码的开始。你只需要添加你在浏览路由器时所做的操作。我希望它能让你开始!你知道吗

import time
from selenium import webdriver
from selenium.common.exceptions import WebDriverException, NoSuchElementException,InvalidElementStateException,ElementNotInteractableException, StaleElementReferenceException, ElementNotVisibleException
from selenium.webdriver.common.keys import Keys
# There may be some unnecessary import above

from selenium.webdriver.chrome.options import Options

options_chrome = webdriver.ChromeOptions()
options_chrome.binary_location = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe' # PATH to your chrome driver (you can also use firefox or any other browser, but options below will not be exactly the same
prefs = {"profile.default_content_setting_values.notifications" : 2} # disable notification by default
options_chrome.add_experimental_option("prefs",prefs)

#### below are options for headless chrome
#options_chrome.add_argument('headless')
#options_chrome.add_argument("disable-gpu")
#options_chrome.add_argument(" start-maximized")
#options_chrome.add_argument(" no-sandbox")
#options_chrome.add_argument(" disable-setuid-sandbox")
#### You should uncomment these lines when your code will be working

# starting browser : 
browser = webdriver.Chrome( options=options_chrome)

# go to the router page :
browser.get("http://192.168.0.1/")

# connect 
elem = browser.find_element_by_id("loginUsername")
elem.send_keys('support')
elem = browser.find_element_by_id("loginPassword")
elem.send_keys('71689637')
elem.send_keys(Keys.RETURN)

# here you need to find your button and click it
button = browser.find_element_by_[Whatever works for you]
button.click()

相关问题 更多 >