python利用selenium+phantomJS爬淘宝

匿名 (未验证) 提交于 2019-12-02 22:54:36


time.sleep(2)

然后你去刚刚的文件看看是不是有一张图片显示出来,对的,就是如下图所示,价格出来了有没有.但是有个问题就是,感觉除了上部分能加载完,其余部分是空白的. ![image.png](https://upload-images.jianshu.io/upload_images/4151356-f67a28728bb08884.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 所以进行第四步,模拟滚动. 4. 模拟滚动,代码如下,我写成函数来调用了,方便调用,还有,一下为完整的代码: ```python #导入selenium from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver = webdriver.PhantomJS(executable_path="phantomjs/bin/phantomjs.exe") #然后填入刚刚的淘宝url driver.get("https://s.taobao.com/search?q=dp%E8%BD%AChdmi&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306") ##然后设置一下模拟浏览器的长宽.我这里假设屏幕是1920*1080的屏幕.! driver.set_window_size(width=1920,height=1080)  ##然后按常理等待2秒钟左右. #time.sleep(2)  ##模拟滚动 def rollView():     global driver     height = 1080     for x in range(12):         jsSQL = "document.body.scrollTop="+str(height)         driver.execute_script(jsSQL)         print(height)         height += 1080         time.sleep(2)  rollView()  ##然后,我们现在尝试一下利用刚刚的模拟浏览器去截图导出看看结果. driver.save_screenshot("taobao.png") 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!