如何打开用户输入的URL?

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

How can I open the url that input by the user

问题

你可以使用以下代码打开用户输入的URL:

  1. from selenium import webdriver
  2. driverPath = "C:/Users/陳子雋/Desktop/Coding Projects/爬蟲/chromedriver.exe"
  3. browser = webdriver.Chrome(driverPath)
  4. url = input()
  5. browser.get(url)
英文:
  1. from selenium import webdriver
  2. import time
  3. driverPath = "C:/Users/陳子雋/Desktop/Coding Projects/爬蟲/chromedriver.exe"
  4. browser = webdriver.Chrome(driverPath)
  5. url = input()
  6. browser.get(url)

How can I open an url that input by user?

答案1

得分: 1

为什么不先获取用户输入,然后像这样初始化webdriver。

  1. from selenium import webdriver
  2. import time
  3. url = input()
  4. driverPath = "C:/Users/陳子雋/Desktop/Coding Projects/爬蟲/chromedriver.exe"
  5. browser = webdriver.Chrome(driverPath)
  6. browser.get(url)
英文:

Why don't you get the user input first and then initialize the webdriver like this.

  1. from selenium import webdriver
  2. import time
  3. url = input()
  4. driverPath = "C:/Users/陳子雋/Desktop/Coding Projects/爬蟲/chromedriver.exe"
  5. browser = webdriver.Chrome(driverPath)
  6. browser.get(url)

答案2

得分: 0

你可以通过首先运行以下命令解决此问题:pip install webbrowser,然后运行以下代码:

  1. import webbrowser
  2. url = input("输入URL")
  3. webbrowser.open(url)
英文:

You can solve this by first running the command pip install webbrowser and then the following code:

  1. import webbrowser
  2. url = input("Enter the URL")
  3. 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:

确定