开发者社区> 问答> 正文

如何更改存储路径:?

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()

展开
收起
游客y6dxbbpsnwo2s 2020-07-21 07:02:10 1665 0
1 条回答
写回答
取消 提交回答
  • 推荐回答

    修改path 和img

    2020-07-21 16:34:48
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
移动与复制 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载