如何打开用户输入的URL?

huangapple go评论153阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年5月30日 12:09:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76361564.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定