擅长:python、mysql、java
<p>由于您提到了“浏览器”和“Chrome”行为,因此可以使用<code>selenium</code>获得与@BurkhanKhalid的正确答案相同的结果:</p>
<pre><code>from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://stackoverflow.com") #Trying http first
url = driver.current_url
>>> print(url[:url.find(":")])
https
</code></pre>