首页 > 代码库 > python — selenium爬取微博指数
python — selenium爬取微博指数
---恢复内容开始---
需要用到的工具:python(pymouse、selenium)、chrome、webdriver
使用的webdriver一定要和chrome的版本相匹配,具体的对应关系可以参考以下博客:http://blog.csdn.net/goblinintree/article/details/47335563。为了避免这个问题,最好直接使用最新的chrome和最新的webdriver。
以下代码是PyMouse的源码
# -*- coding: iso-8859-1 -*- """The goal of PyMouse is to have a cross-platform way to control the mouse. PyMouse should work on Windows, Mac and any Unix that has xlib. See http://code.google.com/p/pymouse/ for more information. """ import sys class PyMouseMeta(object): def press(self, x, y, button = 1): """Press the mouse on a givven x, y and button. Button is defined as 1 = left, 2 = right, 3 = middle.""" raise NotImplementedError def release(self, x, y, button = 1): """Release the mouse on a givven x, y and button. Button is defined as 1 = left, 2 = right, 3 = middle.""" raise NotImplementedError def click(self, x, y, button = 1): """Click the mouse on a givven x, y and button. Button is defined as 1 = left, 2 = right, 3 = middle.""" self.press(x, y, button) self.release(x, y, button) def move(self, x, y): """Move the mouse to a givven x and y""" raise NotImplementedError def position(self): """Get the current mouse position in pixels. Returns a tuple of 2 integers""" raise NotImplementedError def screen_size(self): """Get the current screen size in pixels. Returns a tuple of 2 integers""" raise NotImplementedError if sys.platform.startswith(‘java‘): from java_ import PyMouse elif sys.platform == ‘darwin‘: from mac import PyMouse elif sys.platform == ‘win32‘: from windows import PyMouse else: from unix import PyMouse
由于是windows系统,所以pymouse需要调用windows的win32,否则无法正常使用。
必须要安装win32相关的控件,对应的网址是https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/。请务必选择正确的版本,我的这部分代码使用的是python2.7+64位系统,所以选择的是pywin32-221.win-amd64-py2.7.exe。
完成以上部分的内容之后正式进入到selenium+chrome+python+chrome的爬虫。
python — selenium爬取微博指数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。