from selenium import webdriver
import os
import time
import re
cur_path=os.getcwd() #得到程序的当前目录
str_file=cur_path+'\\sss.txt' #当前目录下的文件
b=webdriver.Chrome() #用Chrome打开
#b.get('https://www.python.org/downloads/windows/')
#s=b.page_source
#打开文件读取得有内容至S字符串
f=open(str_file,'r')
s=f.read()
print(s)
f.close()
print('======================')
r=r'<a href="(.+?\.[ezmc][xish][epim])">'
c_r=re.compile(r,re.I)
url_list=c_r.findall(s)
#显示结果并输出到文件
f=open('out_file','w')
for url_file in url_list:
print(url_file)
f.write(url_file+'\n')
f.close()
time.sleep(2)
b.close()
b.quit()
浙公网安备 33010602011771号