def __login(self):
        # 1.进入登陆页面
        try:
            self.driver.get(self.__login_path)
        except exceptions.TimeoutException:  # 当页面加载时间超过设定时间,JS来停止加载
            self.driver.execute_script('window.stop()')

        # 2.切换到登录iframe
        login_frame = self.driver.find_element_by_id("login_frame")
        self.driver.switch_to_frame(login_frame)

        switch_login_a = self.driver.find_element_by_id("switcher_plogin")
        switch_login_a.click()
        username_input = self.driver.find_element_by_id("u")
        username_input.clear()
        # 点击,防止腾讯判断机器人操作而网络繁忙
        username_input.click()
        username_input.send_keys(self.__username)
        password_input = self.driver.find_element_by_id("p")
        password_input.clear()
        # 点击,防止腾讯判断机器人操作而网络繁忙
        password_input.click();
        password_input.send_keys(self.__password)
        self.driver.find_element_by_id("login_button").click()
        time.sleep(2)
        self.driver.switch_to_default_content()
        try:
            password2_input = self.driver.find_element_by_id("pp")
            if self.__password2 is "":
                print_msg("【邮件】邮箱登录失败,请在__init__.py中配置邮箱独立密码!")
                return False
            password2_input.send_keys(self.__password2)
            self.driver.find_element_by_id("btlogin").submit()
        except exceptions.NoSuchElementException:
            pass
        time.sleep(2)
        try:
            self.driver.find_element_by_id("useralias")
            return True
        except exceptions.NoSuchElementException:
            return False
    def __login(self):
        # 1.进入登陆页面
        try:
            self.driver.get(self.__login_path)
        except exceptions.TimeoutException:  # 当页面加载时间超过设定时间,JS来停止加载
            self.driver.execute_script('window.stop()')

        # 2.切换到登录iframe
        login_frame = self.driver.find_element_by_id("login_frame")
        self.driver.switch_to_frame(login_frame)

        switch_login_a = self.driver.find_element_by_id("switcher_plogin")
        switch_login_a.click()
        username_input = self.driver.find_element_by_id("u")
        username_input.clear()
        # 点击,防止腾讯判断机器人操作而网络繁忙
        username_input.click()
        username_input.send_keys(self.__username)
        password_input = self.driver.find_element_by_id("p")
        password_input.clear()
        # 点击,防止腾讯判断机器人操作而网络繁忙
        password_input.click();
        password_input.send_keys(self.__password)
        self.driver.find_element_by_id("login_button").click()
        time.sleep(2)
        self.driver.switch_to_default_content()
        try:
            password2_input = self.driver.find_element_by_id("pp")
            if self.__password2 is "":
                print_msg("邮箱登录失败,请在__init__.py中配置邮箱独立密码!")
                return False
            password2_input.send_keys(self.__password2)
            self.driver.find_element_by_id("btlogin").submit()
        except exceptions.NoSuchElementException:
            pass
        time.sleep(2)
        try:
            self.driver.find_element_by_id("useralias")
            return True
        except exceptions.NoSuchElementException:
            return False
Ejemplo n.º 3
0
        username_input = driver.find_element_by_id("username")
        username_input.send_keys(self.__username)
        password_input = driver.find_element_by_id("password")
        password_input.send_keys(self.__password)
        submit_input = driver.find_element_by_class_name("logging")
        submit_input.submit()
        time.sleep(3)
        # 3.保存cookies
        list_cookies = driver.get_cookies()
        cookies = {}
        for s in list_cookies:
            cookies[s['name']] = s['value']
            requests.utils.add_dict_to_cookiejar(
                self.__session.cookies, cookies)  # 将获取的cookies设置到session

        driver.switch_to_default_content()  # 返回主页面


if __name__ == '__main__':
    count = 0
    while True:
        down_loader = CsdnDownloader('localhost01', '197347Rcl**')
        local_path = down_loader.download(
            'http://download.csdn.net/download/lqkitten/10113904',
            "c://Robot_Download/")
        if local_path is not None:
            print_msg("下载完成,本地路径:" + local_path + ",重试次数:" + str(count))
            break
        count += 1
Ejemplo n.º 4
0
        if self.__is_logined is False:
            if self.__login() is False:
                return False
            else:
                self.__is_logined = True
        try:
            # 1.进入退款页面
            self.driver.get(self.__refunding_path)
            self.driver.find_element_by_class_name("item-mod__trade-order___2LnGB trade-order-main")
            return True
        except exceptions.NoSuchElementException:
            return False


if __name__ == '__main__':
    # 初始化
    TaobaoClimber.driver = webdriver.Firefox()  # 应将浏览器驱动放于python根目录下,且python已配置path环境变量
    TaobaoClimber.action = ActionChains(TaobaoClimber.driver)
    TaobaoClimber.driver.maximize_window()  # 浏览器最大化
    TaobaoClimber.driver.execute_script("window.open('')")
    TaobaoClimber.driver.execute_script("window.open('')")

    climber = TaobaoClimber(u"淘宝账户", "登录密码")
    while True:
        # 循环爬取订单
        orders = climber.climb()
        for order in orders:
            print_msg("订单号:%s\t订单日期:%s \t买家:%s\t备注:%s" % order)
        # 每30秒抓一次
        time.sleep(30)
Ejemplo n.º 5
0
                return False
            else:
                self.__is_logined = True
        try:
            # 1.进入退款页面
            self.driver.get(self.__refunding_path)
            self.driver.find_element_by_class_name(
                "item-mod__trade-order___2LnGB trade-order-main")
            return True
        except exceptions.NoSuchElementException:
            return False


if __name__ == '__main__':
    # 初始化
    TaobaoClimber.driver = webdriver.Firefox(
    )  # 应将浏览器驱动放于python根目录下,且python已配置path环境变量
    TaobaoClimber.action = ActionChains(TaobaoClimber.driver)
    TaobaoClimber.driver.maximize_window()  # 浏览器最大化
    TaobaoClimber.driver.execute_script("window.open('')")
    TaobaoClimber.driver.execute_script("window.open('')")

    climber = TaobaoClimber(u"淘宝账户", "登录密码")
    while True:
        # 循环爬取订单
        orders = climber.climb()
        for order in orders:
            print_msg("订单号:%s\t订单日期:%s \t买家:%s\t备注:%s" % order)
        # 每30秒抓一次
        time.sleep(30)
Ejemplo n.º 6
0
        password_input.send_keys(self.__password)
        submit_input = self.driver.find_element_by_class_name("logging")
        submit_input.submit()
        time.sleep(3)
        # 3.保存cookies
        list_cookies = self.driver.get_cookies()
        cookies = {}
        for s in list_cookies:
            cookies[s['name']] = s['value']
            requests.utils.add_dict_to_cookiejar(self.__session.cookies, cookies)  # 将获取的cookies设置到session

        self.driver.switch_to_default_content()  # 返回主页面


if __name__ == '__main__':
    # 初始化
    CsdnDownloader.driver = webdriver.Firefox()  # 应将浏览器驱动放于python根目录下,且python已配置path环境变量
    CsdnDownloader.action = ActionChains(CsdnDownloader.driver)
    CsdnDownloader.driver.maximize_window()  # 浏览器最大化
    CsdnDownloader.driver.execute_script("window.open('')")
    CsdnDownloader.driver.execute_script("window.open('')")

    count = 0
    while True:
        down_loader = CsdnDownloader('CSDN VIP账号', 'CSDN VIP密码')
        local_path = down_loader.download('http://download.csdn.net/download/lqkitten/10113904', "c://Robot_Download/")
        if local_path is not None:
            print_msg("下载完成,本地路径:" + local_path + ",重试次数:" + str(count))
            break
        count += 1
Ejemplo n.º 7
0
        if self.__is_logined is False:
            if self.__login() is False:
                return False
            else:
                self.__is_logined = True
        try:
            # 1.进入退款页面
            self.driver.get(self.__refunding_url)
            self.driver.find_element_by_class_name("item-mod__trade-order___2LnGB trade-order-main")
            return True
        except exceptions.NoSuchElementException:
            return False


if __name__ == '__main__':
    # 初始化
    TaobaoClimber.driver = webdriver.Firefox()  # 应将浏览器驱动放于python根目录下,且python已配置path环境变量
    TaobaoClimber.action = ActionChains(TaobaoClimber.driver)
    TaobaoClimber.driver.maximize_window()  # 浏览器最大化
    TaobaoClimber.driver.execute_script("window.open('')")

    climber = TaobaoClimber(u"test", "123456")
    while True:
        # 循环爬取订单
        orders = climber.climb()
        for order in orders:
            print_msg("淘宝订单产生:订单号:%s\t订单日期:%s \t买家:%s\t备注:%s" % order)
        # 每30秒抓一次
        time.sleep(30)
    def __login(self):
        # 1.请求登录页面,获取登录前的必要参数
        html_text = requests.get(self.__login_url).text
        html = BeautifulSoup(html_text, "html5lib")
        form = html.find("form", id="fm1")
        location = form.attrs["action"]  # 每次表单action后面有个随机数
        lt = form.select("input[name=lt]")[0].attrs["value"]
        execution = form.select("input[name=execution]")[0].attrs["value"]
        _eventId = form.select("input[name=_eventId]")[0].attrs["value"]
        params = {"username": self.__username, "password": self.__password, "lt": lt, "execution": execution,
                  "_eventId": _eventId}

        time.sleep(1)  # CSDN貌似判断机器人,睡眠一下,增加成功率

        # 2.进行登录
        response = requests.post(location, params)

        # 3.保存cookies
        self.__session.cookies = response.cookies
        self.__is_logined = True


if __name__ == '__main__':
    down_loader = CsdnDownloader("test", "123456")
    local_path = down_loader.download('http://download.csdn.net/download/lqkitten/10113904', "c://Robot_Download/")
    if local_path is not None:
        print_msg("CSDN下载完成,本地路径:" + local_path)
    else:
        print_msg("CSDN下载失败")
Ejemplo n.º 9
0
        vip_download_a.click()
        time.sleep(2)
        # 1.切换到登录iframe
        form_iframe = driver.find_element_by_xpath("//*[@id='loginWrap']/iframe")
        driver.switch_to_frame(form_iframe)
        # 2.进行登录
        username_input = driver.find_element_by_id("username")
        username_input.send_keys(self.__username)
        password_input = driver.find_element_by_id("password")
        password_input.send_keys(self.__password)
        submit_input = driver.find_element_by_class_name("logging")
        submit_input.submit()
        time.sleep(3)
        # 3.保存cookies
        list_cookies = driver.get_cookies()
        cookies = {}
        for s in list_cookies:
            cookies[s['name']] = s['value']
            requests.utils.add_dict_to_cookiejar(self.__session.cookies, cookies)  # 将获取的cookies设置到session

        driver.switch_to_default_content()  # 返回主页面


if __name__ == '__main__':
    count = 0
    while True:
        count += 1
        down_loader = CsdnDownloader('csdn_vip账号', '登录密码')
        local_path = down_loader.download('http://download.csdn.net/download/lqkitten/10113904', "c://Robot_Download/")
        print_msg("下载完成,本地路径:" + local_path + "__" + count)