[Python] 纯文本查看 复制代码
from selenium import webdriver
import win32api
import win32con
import win32clipboard
from ctypes import *
import time
import requests
import docx
import os,sys
import re
driver = webdriver.Edge(r'F:\winGUI\edge\msedgedriver.exe')#浏览器的驱动路径
def ge(url):
driver.get(url)
a = driver.find_element_by_class_name("rich_media_title")
b = a.text#获取标题
rule = r'?*:"<>\/|'#文件命名不能有这些因为就去掉
for c in rule:
b = b.replace(c,"")
with open('0011.txt', 'a+') as f:
f.write(b+'.docx'+'\n')#把标题写到文本
doc = docx.Document()
doc.save(b)#读取文本新建word
for x in range(20):#滑动次数 最好是改大点
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL,0,0,-500)#鼠标滑动
time.sleep(3)
win32api.keybd_event(0x11, 0, 0, 0)#ctrl
win32api.keybd_event(0x41, 0, 0, 0)#a
win32api.keybd_event(0x41, 0, win32con.KEYEVENTF_KEYUP, 0)#a
win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)#释放按键
time.sleep(3)
win32api.keybd_event(0x11, 0, 0, 0)#ctrl
win32api.keybd_event(0x43, 0, 0, 0)#c
win32api.keybd_event(0x43, 0, win32con.KEYEVENTF_KEYUP, 0)#c
win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)#释放按键
time.sleep(3)
with open("0011.txt", "r") as f:
data = f.readline()
print(data)
aa = data
result = os.popen(aa)
time.sleep(1)
with open('0011.txt', 'r',encoding='gbk') as f:
line = f.readlines() # 读取文件
line = line[1:] # 只读取第一行之后的内容
f = open('0011.txt', mode='w', encoding='gbk') # 以写入的形式打开txt文件
f.writelines(line) # 将修改后的文本内容写入
time.sleep(6)
win32api.keybd_event(0x11, 0, 0, 0)#ctrl
win32api.keybd_event(0x56, 0, 0, 0)#v
win32api.keybd_event(0x56, 0, win32con.KEYEVENTF_KEYUP, 0)#v
win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)#释放按键
time.sleep(3)
win32api.keybd_event(0x11, 0, 0, 0)#ctrl
win32api.keybd_event(0x53, 0, 0, 0)#s
win32api.keybd_event(0x53, 0, win32con.KEYEVENTF_KEYUP, 0)#s
win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)#释放按键
time.sleep(3)
os.system("taskkill /IM WINWORD.EXE")#结束进程,不结束的话有时候会被占用
with open("urls.txt",'r') as f:
urls = f.readlines()
for url in urls:
ge(url)
driver.close()