import time
from selenium import webdriver
def update():
options = webdriver.ChromeOptions()
driver = webdriver.Chrome('./chrome-win/chromedriver.exe',options=options)
driver.get('http://www.xuexila.com/gzzongjie/nian/c202270.html')
tbv2 = driver.find_element_by_id('contentText')
# 等待页面中的文本填充完成
while True:
if len(tbv2.text.split('\n')) >0:
break
else:
time.sleep(1)
continue
s1 = tbv2.text.split('\n')
driver.quit()
if len(s1) < 2:
print("请重新运行命令获取")
return None
else:
print("获取成功")
return s1
if __name__ == "__main__":
s1=update()
with open('result.txt','w+',encoding='utf-8') as f:
for s in s1:
f.write(' {0}\n'.format(s))
print("共写入{0}行".format(len(s1)))
|