使用无界面浏览器实现豆瓣电影的异步加载

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/g_optimistic/article/details/89887648

目录

1.查找接口

2.导入模块,创建浏览器对象

3.请求接口

4.模拟滚动条滚动到底部

5.查看效果


豆瓣电影:https://movie.douban.com/

想要查找豆瓣电影排行榜的剧情里面的

1.查找接口

https://movie.douban.com/typerank?type_name=%E5%89%A7%E6%83%85&type=11&interval_id=100:90&action=

2.导入模块,创建浏览器对象

from selenium import webdriver
import time
driver=webdriver.PhantomJS(executable_path=r'F:\1210\phantomjs-2.1.1-windows\phantomjs-2.1.1-windows\bin\phantomjs.exe')

3.请求接口

driver.get('https://movie.douban.com/typerank?type_name=%E5%89%A7%E6%83%85&type=11&interval_id=100:90&action=')
time.sleep(3)
driver.save_screenshot('08_01.png')

4.模拟滚动条滚动到底部

# 向下滚动10000像素
js = 'document.body.scrollTop=10000'
# 执行JS语句
driver.execute_script(js)
# 查看页面快照
time.sleep(5)
driver.save_screenshot('08_02.png')

5.查看效果

08_01.png

08_02.png

猜你喜欢

转载自blog.csdn.net/g_optimistic/article/details/89887648