标签:url inter local pad nts port www 图片 cli
1、上传
学习链接:
https://www.cnblogs.com/yoyoketang/p/6445270.html
input标签可以借助send_keys()操作来实现文件上传
<<input type="file" name="file" style="position: absolute; right: 0px; top: 0px; font-family: Arial; font-size: 118px; margin: 0px; padding: 0px; cursor: pointer; opacity: 0;">>
参考代码如下:
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time option = webdriver.ChromeOptions() option.add_argument(r‘--user-data-dir=C:\Users\yl8\AppData\Local\Google\Chrome\User Data1‘) driver = webdriver.Chrome(options=option) # driver.get("http://www.cnblogs.com/") blogurl = "http://www.cnblogs.com/" myblog = blogurl + "my" driver.get(myblog) driver.refresh() driver.find_element_by_id("blog_nav_newpost").send_keys(Keys.ENTER) time.sleep(10) driver.find_element_by_xpath(‘//*[@id="post-title"]‘).send_keys(edit_title)# 点开编辑器图片 driver.find_element_by_css_selector("img.mceIcon").click() time.sleep(3) # 定位所有iframe,取第二个 iframe = driver.find_elements_by_tag_name("iframe")[1] # 切换到iframe上 driver.switch_to.frame(iframe) # 文件路径
driver.find_element_by_name("file").send_keys(r"xxx\图片.jpg")
标签:url inter local pad nts port www 图片 cli
原文地址:https://www.cnblogs.com/yuer02/p/12620113.html