简体   繁体   English

如何使用 selenium 登录

[英]How to Log-in using selenium


I am trying to scrape data from this Web我正在尝试从此Web中抓取数据

I need to login here .我需要在这里登录。

Here is my code .这是我的代码

I dont really know how to do that.我真的不知道该怎么做。 How can do this?怎么能做到这一点? ... ...
Sincerely thanks.衷心感谢。 <3 <3

To login you can go directly to the login page and then go to the page you want to scrape.要登录,您可以 go 直接到登录页面,然后 go 到您要抓取的页面。

You have to download chromedriver from here and specify the path on my script.您必须从此处下载 chromedriver 并在我的脚本中指定路径。

This is how you can do it:您可以这样做:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path=r'PATH')#PUT YOUR CHROMEDRIVER PATH HERE

driver.get("https://secure.vietnamworks.com/login/vi?client_id=3") #LOGIN URL

driver.find_element_by_id("email").send_keys("YOUR-EMAIL@gmail.com") #PUT YOUR EMAIL HERE
driver.find_element_by_id('login__password').send_keys('PASSWORD') #PUT YOUR PASSWORD HERE

driver.find_element_by_id("button-login").click()

driver.get("https://www.vietnamworks.com/technical-specialist-scientific-instruments-lam-viec-tai-hcm-chi-tuyen-nam-tuoi-tu-26-32-chi-nhan-cv-tieng-anh-1336108-jv/?source=searchResults&searchType=2&placement=1336109&sortBy=date") #THE WEB PAGE YOU NEED TO SCRAPE

And then you can get the data from the web page.然后您可以从 web 页面获取数据。

I don't think you need to use your main page a navigate tru that.我不认为你需要使用你的主页来导航。 You can just use the link https://www.vietnamworks.com/dang-nhap?from=home-v2&type=login and then write your credentials to the page that loads.您可以使用链接https://www.vietnamworks.com/dang-nhap?from=home-v2&type=login然后将您的凭据写入加载的页面。

After the page loads, you use页面加载后,您使用

find_element_by_xpath("""//*[@id="email"]""").send_keys("youremail")
password_element = find_element_by_xpath("""//[@id="login__password"]""").send_keys("yourpassword")
password_element.submit()

Xpath is obviously the xpath to the element you need. Xpath 显然是您需要的元素的 xpath。 .submit() is the same as using enter . .submit()与使用enter相同。

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

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