英文:
How can I open the url that input by the user
问题
你可以使用以下代码打开用户输入的URL:
from selenium import webdriver
driverPath = "C:/Users/陳子雋/Desktop/Coding Projects/爬蟲/chromedriver.exe"
browser = webdriver.Chrome(driverPath)
url = input()
browser.get(url)
英文:
from selenium import webdriver
import time
driverPath = "C:/Users/陳子雋/Desktop/Coding Projects/爬蟲/chromedriver.exe"
browser = webdriver.Chrome(driverPath)
url = input()
browser.get(url)
How can I open an url that input by user?
答案1
得分: 1
为什么不先获取用户输入,然后像这样初始化webdriver。
from selenium import webdriver
import time
url = input()
driverPath = "C:/Users/陳子雋/Desktop/Coding Projects/爬蟲/chromedriver.exe"
browser = webdriver.Chrome(driverPath)
browser.get(url)
英文:
Why don't you get the user input first and then initialize the webdriver like this.
from selenium import webdriver
import time
url = input()
driverPath = "C:/Users/陳子雋/Desktop/Coding Projects/爬蟲/chromedriver.exe"
browser = webdriver.Chrome(driverPath)
browser.get(url)
答案2
得分: 0
你可以通过首先运行以下命令解决此问题:pip install webbrowser
,然后运行以下代码:
import webbrowser
url = input("输入URL")
webbrowser.open(url)
英文:
You can solve this by first running the command pip install webbrowser
and then the following code:
import webbrowser
url = input("Enter the URL")
webbrowser.open(url)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论