前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python — selenium爬取微博指数

python — selenium爬取微博指数

作者头像
Mister24
发布2018-05-14 10:52:54
1K0
发布2018-05-14 10:52:54
举报
文章被收录于专栏:java初学java初学

---恢复内容开始---

需要用到的工具:python(pymouse、selenium)、chrome、webdriver

使用的webdriver一定要和chrome的版本相匹配,具体的对应关系可以参考以下博客:http://blog.csdn.net/goblinintree/article/details/47335563。为了避免这个问题,最好直接使用最新的chrome和最新的webdriver。

以下代码是PyMouse的源码

代码语言:javascript
复制
# -*- 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的爬虫。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-05-07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档