通过百度首页,上传图片
1 #!/usr/bin/env python 2 # coding:utf-8 3 # 上传文件 4 from selenium import webdriver 5 from time import sleep,ctime 6 from selenium.common.exceptions import InvalidArgumentException 7 8 driver = webdriver.Chrome() 9 driver.get(r"http://www.baidu.com") 10 11 driver.find_element_by_css_selector("span.bg.s_ipt_wr.quickdelete-wrap > .soutu-btn").click() 12 sleep(2) 13 print('---------------%s-------------------' % ctime()) 14 try: 15 driver.find_element_by_xpath('//form[@id="form"]//input[@type="file" and @class="upload-pic"]').send_keys(r'D:11.jpg') 16 except InvalidArgumentException as msg: 17 print(msg) 18 finally: 19 sleep(3) 20 print('---------------%s-------------------' % ctime()) 21 driver.quit()