url='https://cn.bing.com/images/search?view=detailV2&ccid=7CuBKaoi&id=E698AB4A2D32505E1EF6AEBFD9C794D1742088E1&thid=OIP.7CuBKaoiHHVek4wk1cJnewHaEF&mediaurl=https%3a%2f%2fn.sinaimg.cn%2ftech%2ftransform%2f178%2fw630h348%2f20180327%2fkk33-fysqfnh4539043.jpg&exph=348&expw=630&q=%e6%89%8e%e5%85%8b%e4%bc%af%e6%a0%bc&simid=608036999620591627&ck=D6E69642C0BFDED4808B19D937157106&selectedIndex=3&ajaxhist=0'
import requests import random from selenium import webdriver import win32api import win32con import win32clipboard from ctypes import * from selenium.webdriver.common.action_chains import ActionChains import time import re from lxml import etree
def keyDown(keyName): win32api.keybd_event(VK_CODE[keyName],0,0,0) def keyUp(keyName): win32api.keybd_event(VK_CODE[keyName],0,win32con.KEYEVENTF_KEYUP,0) VK_CODE={'enter':0x0D,'down_arrow':0x28}
browser = webdriver.Chrome() browser.maximize_window()
browser.get(url)
time.sleep(2)
path = 'F:\spider\' win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(path) win32clipboard.CloseClipboard()
img = browser.find_element_by_xpath('//*[@id="mainImageWindow"]/div[2]/div/div/div/img')
action = ActionChains(browser).move_to_element(img)
action.context_click(img).perform()
time.sleep(1)
win32api.keybd_event(86, 0, 0, 0)
time.sleep(1)
win32api.keybd_event(0x11, 0, 0, 0) win32api.keybd_event(0x56, 0, 0, 0) win32api.keybd_event(0x56, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)
win32api.keybd_event(0x0D, 0, 0, 0)
win32api.keybd_event(0x12, 0, 0, 0) win32api.keybd_event(0x53, 0, 0, 0) win32api.keybd_event(0x53, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(0x12, 0, win32con.KEYEVENTF_KEYUP, 0)
keyDown('enter')
keyUp('enter')
time.sleep(1)
print('over')
browser.close()
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。