Exemple #1
0
 async def getPage(self, url):
     async with RequestManager().session as session:
         async with session.get(url, headers=self.headers) as resp:
             print("java_codeceo 1111", resp.status)
             assert resp.status == 200
             r_body = await resp.text(errors="ignore")
             rp = Response()
             rp.url = url
             rp.body = r_body
             return rp
 async def getPage1(self, response):
     self.headers["Referer"] = response["url"].get("upper_url")
     async with RequestManager().session as session:
         async with session.get(response["url"].get("url"), headers=self.headers) as resp:
             print("java_csdn 222", resp.status)
             # print("222url", url.get("url"))
             assert resp.status == 200
             # print("222upper_url", url.get("upper_url"))
             # errors="ignore",忽略非法字符
             r_body = await resp.text(errors="ignore")
             rp = Response()
             rp.url = response["url"].get("url")
             rp.body = r_body
             rp.meta = response["meta"]
             return rp
Exemple #3
0
    def send_request(**kwargs):
        """
        :param args:
        :param kwargs:
            接口名称         name
            请求方式         method
            参数             data
            用户             user
            是否重定向       allow_redirects
            可选参数超时时间  time_out
        :return:
        """

        res, html = RequestManager.send_requests(**kwargs)
        print('---------------------------------------------<br>')
        print('本次请求返回:::>>' + str(html))
        print('---------------------------------------------<br>')
        return res, html
Exemple #4
0
async def getPage(url):
    # asyncio.Semaphore(),限制同时运行协程数量
    sem = asyncio.Semaphore(5)
    with (await sem):
        async with RequestManager().session as session:
            async with session.get(url, headers=headers, timeout=360) as resp:
                # 暂停一会儿,太不暗落落容易被封
                time.sleep(random.random() * 5)
                # 断言,判断网站状态
                assert resp.status == 200
                # 判断不同url做不同的处理
                if "xicidaili" in url:
                    body = await resp.text()
                    xici_grabPage(url, body)
                elif "kuaidaili" in url:
                    body = await resp.text()
                    kuaidaili_grabPage(url, body)
                elif "nianshao" in url:
                    body = await resp.text()
                    nianshao_grabPage(url, body)
                elif "66ip" in url:
                    body = await resp.text()
                    ip66_grabPage(url, body)
                elif "httpsdaili" in url:
                    body = await resp.text()
                    httpsdaili_grabPage(url, body)
                elif "swei360" in url:
                    body = await resp.text()
                    swei360_grabPage(url, body)
                elif "kxdaili" in url:
                    body = await resp.text()
                    kxdaili_grabPage(url, body)
                else:
                    return await resp.text()
                # 关闭请求
                session.close()
Exemple #5
0
SERVER_PORT = 1024

if __name__ == '__main__':
    print 'Argument List: ', str(sys.argv)

    if len(sys.argv) > 1:
        port = int(sys.argv[1])
    else:
        port = SERVER_PORT

    exe_folder_str = get_file_folder(sys.argv[0])
    ConfigurationParser.set_root_folder(exe_folder_str)

    request_handler = NetscoutRequestHandler()

    request_manager = RequestManager()
    request_manager.bind_command(
        'login', (NetscoutRequestHandler.login, request_handler))
    request_manager.bind_command(
        'logout', (NetscoutRequestHandler.logout, request_handler))
    request_manager.bind_command(
        'getresourcedescription',
        (NetscoutRequestHandler.get_resource_description, request_handler))
    request_manager.bind_command(
        'setstateid', (NetscoutRequestHandler.set_state_id, request_handler))
    request_manager.bind_command(
        'getstateid', (NetscoutRequestHandler.get_state_id, request_handler))
    request_manager.bind_command(
        'mapbidi', (NetscoutRequestHandler.map_bidi, request_handler))
    request_manager.bind_command(
        'mapuni', (NetscoutRequestHandler.map_uni, request_handler))

if __name__ == '__main__':
    print 'Argument List: ', str(sys.argv)

    if len(sys.argv) > 1:
        port = int(sys.argv[1])
    else:
        port = SERVER_PORT

    exe_folder_str = get_file_folder(sys.argv[0])
    ConfigurationParser.set_root_folder(exe_folder_str)

    request_handler = NetscoutRequestHandler()

    request_manager = RequestManager()
    request_manager.bind_command('login', (NetscoutRequestHandler.login, request_handler))
    request_manager.bind_command('logout', (NetscoutRequestHandler.logout, request_handler))
    request_manager.bind_command('getresourcedescription', (NetscoutRequestHandler.get_resource_description,
                                                            request_handler))
    request_manager.bind_command('setstateid', (NetscoutRequestHandler.set_state_id, request_handler))
    request_manager.bind_command('getstateid', (NetscoutRequestHandler.get_state_id, request_handler))
    request_manager.bind_command('mapbidi', (NetscoutRequestHandler.map_bidi, request_handler))
    request_manager.bind_command('mapuni', (NetscoutRequestHandler.map_uni, request_handler))
    request_manager.bind_command('mapclearto', (NetscoutRequestHandler.map_clear_to, request_handler))
    request_manager.bind_command('mapclear', (NetscoutRequestHandler.map_clear, request_handler))
    request_manager.bind_command('setspeedmanual', (NetscoutRequestHandler.set_speed_manual, request_handler))

    server_connection = ServerConnection(SERVER_HOST, port, request_manager, exe_folder_str)
    server_connection.start_listeninig()