按照正常的步骤:
我们先写一个powershell代码,然后运行,即可用谷歌浏览器打开网页
然后键入快捷键Ctrl+W即可关闭掉这个页签。
当我们把这一切自动化,我们访问网页就可以像看电影一样啦。
为了保证有足够的时长,这里我们通过从txt文件里读取网页的方式来实现。当然,您也可以收藏网页来方便自己下一次访问。
话不多说,直接上代码啦:
#! python3
import pyautogui,time,requests,os,subprocess
def quitthesite():
a=1
while a >0:
time.sleep(5)
pyautogui.hotkey("ctrl","w")
a-=1
def gettheurl(url):
try:
res = requests.get(url)
res.raise_for_status()
quitthesite()
f=open(secname1,'w')
#FILENAMEIS
f.write('start "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" '+str(url))
f.close()
time.sleep(0.05)
res = subprocess.Popen(['C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe','C:\\Users\\Administrator\\Desktop\\OI\\rdpen.ps1'])
res.wait()
except Exception as exc:
print('sthwrong')
def dothem(f):
#print(fname)
urlsets =open(fname)
urls=urlsets.readlines()
for url in urls:
url =str(url)
url =url.strip('\n')
print(str(url))
#url= url.lower()
if (str(url)[0:1] == 'w' or str(url)[0:1] == 'h'or str(url)[0:1] == 'W'or str(url)[0:1] == 'H' ):
if str(url)[0:1] == 'w':
url = 'http://'+str(url)
if str(url)[0:1] == 'W':
url = 'http://'+str(url)
gettheurl(str(url))
# 获取文件名后缀
def get_file_tail(file_name=''):
# 获取文件后缀名
file_arr = file_name.split(".")
if len(file_arr) >= 2:
return file_arr[len(file_arr) - 1].lower()
else:
return 'default'
def movefrmeatob(a,b):
filenamesa = str(a)
folderb = 'C:\\Users\\Administrator\\Desktop\\'+str(b)
shutil.move(filenamesa,folderb)
try:
os.chdir('C:\\Users\\Administrator\\Desktop')
except Exception as exc:
print(1)
filebs = os.getcwd()
#print(filebs)
#print(fileII)
foleOI = 'C:\\Users\\Administrator\\Desktop\\OI'
#print(foleOI)
os.makedirs(fileII)
os.makedirs(foleOI)
gettheurl(url)
gettheurl(url)
for folderName,subfolders,filenames in os.walk('C:\\Users\\Administrator\\Desktop\\II'):
for filename in filenames:
if get_file_tail(filename) == 'txt':
dothem(filename)
shutil.move(filenamesa,foleOI)
quitthesite()
quitthesite()
领取专属 10元无门槛券
私享最新 技术干货