from selenium import webdriver
import time
def renrenBrower(user, password):
try:
opt = webdriver.ChromeOptions()
opt.headless = True
driver = webdriver.Chrome(options=opt)
driver.get('https://这里输入登录的网址/')
time.sleep(2)
driver.find_element_by_xpath('//*[@id="uid"]').send_keys(user)
driver.find_element_by_xpath('//*[@id="password"]').send_keys(password)
driver.find_elements_by_xpath('//div[@class="u-form-item u-form-item-2"]/button')[0].click()
time.sleep(2)
if len(driver.find_elements_by_xpath('//div[@class="msgFrame"]')):
print("success")
else:
print("fail")
except Exception as e:
print(str(e))
if __name__ == '__main__':
renrenBrower('用户名', '密码')
公司需求写个爬虫模拟登录,环境下需要准备chromedriver.exe [http://npm.taobao.org/mirrors/chromedriver/]这个网址下载(http://npm.taobao.org/mirrors/chromedriver/)
|