简体   繁体   English

无法用selenium python打开URL,但浏览器打开成功

[英]Cannot open up URL with selenium python, but the browser is succesfully opened

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
import datetime


ch_options = webdriver.ChromeOptions()
ch_options.add_argument("--user-data-dir=C:\\Users\\Dossy\\AppData\\Local\\Google\\Chrome\\User Data")


chrome = webdriver.Chrome(options=ch_options)

chrome.get("https://www.google.com/")

this code only open up the chromedriver with my profile, but couldn't redirect to a link此代码仅使用我的个人资料打开 chromedriver,但无法重定向到链接

Instead of writing this:而不是写这个:

ch_options = webdriver.ChromeOptions()
ch_options.add_argument("--user-data-dir=C:\\Users\\Dossy\\AppData\\Local\\Google\\Chrome\\User Data")

you can directly give the path你可以直接给出路径

ch_options = webdriver.Chrome('**HERE GIVE  YOUR FULL PATH OF chromedriver.exe**')

like:喜欢:

chrome = webdriver.Chrome('C:\\Users\\Lucky\\Downloads\\.zip\\chromedriver.exe')

Your browser will open and it and will also redirect you to the link.您的浏览器将打开,它还会将您重定向到该链接。

Try this with your correct driver path用正确的驱动程序路径试试这个

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
import datetime

chromedriver = 'path of chrome driver till chromedriver.exe'
driver = webdriver.Chrome(chromedriver)
driver.get("https://www.google.com/")

Making it so simple and short: Make sure to add the chrome driver path correctly让它变得如此简单和简短:确保正确添加chrome驱动程序路径

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
import datetime

PATH = r"C:\Program Files (x86)\chromedriver.exe"    # Path where u have downloaded the driver

driver = webdriver.Chrome(PATH)

driver.get("https://www.google.com")

This will work hopefully!这将有希望地工作!

If you have problem in first solution and try this: First copy the of chrome driver path:如果您在第一个解决方案中遇到问题,请尝试以下操作:首先复制 chrome 驱动程序路径: 在此处输入图片说明

Then,go to the "This PC" and right click on it and then go to the properties:然后,转到“此PC”并右键单击它,然后转到属性: 在此处输入图片说明

After it go to the advanced system setting:进入高级系统设置后: 在此处输入图片说明

Then, click on Environment Variable然后点击环境变量在此处输入图片说明

Then,In system variable click on Path and then click on edit:然后,在系统变量中点击路径,然后点击编辑: 在此处输入图片说明

Then, click on new :然后,点击新建: 在此处输入图片说明

After it,paste the copied path with \\chromedriver.exe then click on "Ok":之后,用 \\chromedriver.exe 粘贴复制的路径,然后单击“确定”: 在此处输入图片说明

and click "Ok" on all the tabs That's it Now try it Comment if you are having still problem in this.并在所有选项卡上单击“确定” 就是这样 现在尝试评论 如果您在这方面仍有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM