Python环境
3.6.1
本地URL链接文件
https://blog.csdn.net/fly910905/article/details/83418623 https://blog.csdn.net/fly910905/article/details/83417911 https://blog.csdn.net/fly910905/article/details/83144267 https://blog.csdn.net/fly910905/article/details/83143153 https://blog.csdn.net/fly910905/article/details/83055987 https://blog.csdn.net/fly910905/article/details/83022524 https://blog.csdn.net/fly910905/article/details/82868342 https://blog.csdn.net/fly910905/article/details/82869328 https://blog.csdn.net/fly910905/article/details/82869344 https://blog.csdn.net/fly910905/article/details/82800533
Python完整代码
# 导入 webdriver from selenium import webdriver # 读取本地文件中的URL链接 address = './url.txt' fp = open(address, 'r') lines = fp.readlines() print('【URL链接】:%s', lines) # 调用环境变量指定的PhantomJS浏览器创建浏览器对象 driver = webdriver.PhantomJS() # 如果没有在环境变量指定PhantomJS位置 # driver = webdriver.PhantomJS(executable_path="./phantomjs")) for data in lines: # get方法会一直等到页面被完全加载,然后才会继续程序,通常测试会在这里选择 time.sleep(2) driver.get(data) # 向下滚动10000像素 js = "document.body.scrollTop=10000" # js="var q=document.documentElement.scrollTop=10000" # 执行JS语句 driver.execute_script(js) # 查看页面快照 # driver.save_screenshot("csdn.png") print('执行中。。。') # 关闭浏览器 driver.quit() print('执行结束。。。') # 关闭文件流 fp.close()