PYTHON

    wda玩微信跳一跳

    … 等我写完这个脚本,刷到了372分, 才发现Android的大佬们早就有一套操作了, 似乎想法都差不多,我的环境是在ios-mac上执行

    安装环境

    WebDriverAgent

    https://github.com/facebook/WebDriverAgent
    facebook开源的自动化驱动框架, 调的私有Api,所以执行的速度应该说是最准的,这也是这套玩法的关键点
    需要一些环境依赖,代码clone下来之后, 得在项目路径下执行下:

    ./Scripts/bootstrap.sh
    

    xcode打开,选择Target是WebDriverAgentRunner,Test到手机(签名用个人Appid就可以,然后Test到手机后,信任一下证书)

    facebook-wda

    https://github.com/openatx/facebook-wda
    wda,一个python脚本,配合WebDriverAgent使用,便捷的安装方法:

    sudo pip install --pre facebook-wda
    

    测试下环境

    用个终端端口转发下(iproxy 可以通过 brew install usbmuxd安装):

    iproxy 8100 8100
    

    用以下命令启动下WebDriverAgent,你需要改下下方的name=你自己的手机名:

    xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'platform=iOS,name=YourDeviceName' test
    

    看到输出这个就启动正常了:

    另开个终端,启动下python,如下测试下:

    脚本实现:

    git代码地址-python3.6.3

    IMAGE_PLACE = '/tmp/screen.webp'
    each_pixel_d = 0.00190
    c = wda.Client()
    s = c.session('com.tencent.xin')
    input("请自行切换到游戏里面的界面,回车即可开始")
    
    def change_to_duration(position_list):
        """
        勾股定理 求d=C=开根号(A^2+B^2)
        """
        if not position_list:
            return
        x1,y1 = position_list[0]
        x2,y2 = position_list[1]
        the_d = math.sqrt(math.pow(y2 - y1, 2) + math.pow(x2 - x1, 2))
        return float('%.3f' % (the_d * each_pixel_d))
    
    if __name__ == '__main__':
        while 1:
            x = c.screenshot(IMAGE_PLACE)
            if not os.path.exists(IMAGE_PLACE):
                continue
            # time.sleep(1)  #图片就算在了,渲染还没结束,这1秒阻塞就给了吧,或者不给,为渲染正常的以下方阴影为准
            pl.imshow(pl.array(Image.open(IMAGE_PLACE)))
            position_list = pl.ginput(2,timeout=2147483647)
            pl.ion()
            duration = change_to_duration(position_list)
            pl.ioff()
            if duration and os.path.exists(IMAGE_PLACE):
                s.tap_hold(200, 200, duration=duration)
                os.remove(IMAGE_PLACE)
    

    首先进入到游戏页面,截图到本地
    使用plt.imshow展示这张图片, 通过plt.ginput我们点击的两个点会被记录下来,
    我们通过分析这两个点, 得到小人到对面物体的地点:
    嗯, 勾股定理:

    Dec 30, 2017
    Python

    seleniumANDrequest辅助爬虫

    爬虫写多了时候会发现, 很多的时候总是有些问题被阻挡, 虽然越来越多的AI诸如此类的工具也正在破解升级, 但在在小型的爬虫之前,selenium可以帮助我们辅助一些代码层无法越过的坑,拿到完整的cookies, 让客户端对我们身份证验证已通过之后,移交到深层的代码里, 进行操作.

    先用selenium拿到最真实的cookies

    似乎这没什么好讲的, 贴下我的代码截图吧…
    selenium小封装:

    小爬虫的时候或许都可以跳过这一步, 你可以进行一个长时间的sleep,手工进行登录,填入验证码等

    cookies移交

    def set_session_cookie(self):
        """
        cookie 移植到 session,方便后续操作
        """
        self.driver.get('http://url')
        for subCookie in self.driver.get_cookies():
            self.session.cookies.set(subCookie[u'name'], self.driver.get_cookie(subCookie[u'name'])['value'])
    

    self.driver.get_cookies() 得到是一个数组, 我们遍历这个数组, 拿到name-value , 对移交的session的进行cookies设置.

    Nov 23, 2017
    Python