-3

I'm new in Python, how can I add https:// into "url = sys.argv[1]"?

Below is my script, what can I improve from here?

import sys
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

url = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]

options = Options()
options.add_argument('--allow-running-insecure-content')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--start-maximized')

driver = webdriver.Chrome(options=options)
driver.get(url)
driver.implicitly_wait(5)
driver.find_element_by_id("name").send_keys(username)
driver.find_element_by_id("passwd").send_keys(password)
driver.find_element_by_id("login").click()
khelwood
  • 55,782
  • 14
  • 81
  • 108
GeorgeW
  • 23
  • 3

2 Answers2

0
url = 'https://' + sys.argv[1]

If you just want to add https:// you can just concatenate string by using + operator

Best solution is you can check with other condition if url already have http as prefix if not then add:

url = sys.argv[1]
if((sys.argv[1]).startswith('http')):
    url = 'https://' + sys.argv[1]
yash jain
  • 60
  • 9
0

I think you can do url = 'https://'+ sys.argv[1] if sys.argv[1] is google.com url will be https://google.com

Best regards

TOTO
  • 307
  • 1
  • 6
  • thank you, is working. If I want to add port no 54321, can I do like url = 'https://'+ sys.argv[1]':54321' – GeorgeW Nov 07 '20 at 13:50
  • If you want to add the port to the url you can do it with url = 'https://'+ sys.argv[1] + ':54321' . You can use the + sign to concatenate string in python https://www.pythonforbeginners.com/concatenation/string-concatenation-and-formatting-in-python – TOTO Nov 07 '20 at 18:10