当前位置: 首页>>代码示例>>Python>>正文


Python PyQuery.decode方法代码示例

本文整理汇总了Python中pyquery.PyQuery.decode方法的典型用法代码示例。如果您正苦于以下问题:Python PyQuery.decode方法的具体用法?Python PyQuery.decode怎么用?Python PyQuery.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyquery.PyQuery的用法示例。


在下文中一共展示了PyQuery.decode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: try_account

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import decode [as 别名]
def try_account(id_list, default_pass):
    """
    暴力破解帐号密码
    :param id_list:帐号列表
    :param default_pass:默认密码
    :return:
    """
    for id_item in id_list:
        form_data['loginName'] = str(id_item)  # 将用户名填入表单
        form_data['password'] = default_pass  # 将密码填入表单
        code_img_name = get_code_img()
        code_str = code_img_to_string(code_img_name)
        form_data['verify'] = code_str  # 验证码填入表单
        result = login()  # 登录,获取返回的 response 结果
        print form_data
        err_msg = Pq(result).find('.login_panel .ul_login li:eq(4) span').text()
        print err_msg.decode('utf-8')
        if err_msg == u'验证码错误':
            # 获取验证码重新登录
            code_img_name = get_code_img()
            code_str = code_img_to_string(code_img_name)
            form_data['verify'] = code_str
            result = login()
        if err_msg == u'用户名或者密码错误':
            continue
        if err_msg is None:
            print '成功破解:' + str(id_item) + "\t" + result  # 打印成功登录的帐号
开发者ID:AliceLanniste,项目名称:python,代码行数:29,代码来源:tarena_tts5.py

示例2: import_team

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import decode [as 别名]
def import_team(rootpage, session, event):
    """Imports multiple Players a time from a external Site.
       Currently only working with Transfermarkt.ch

    """
    headers = {"User-agent": "Mozilla/5.0"}
    for page in rootpage:
        f = requests.get(page, headers=headers)
        nationpage = f.content
        nationpage = PyQuery(nationpage.decode("utf8"))
        content = nationpage("#main")
        nation_name = content(".box-header .spielername-profil").text()
        country_code = COUNTRY_CODE_MAPPING[nation_name]

        # Lookup nation
        nation = session.query(Nation).filter(Nation.country == country_code).first()
        # Create a new nation if we didn't find one
        if nation is None:
            nation = Nation(nation_name, event, country_code)
            nation.country = country_code
            session.add(nation)

        playertable = content("table.items")
        playerlist = playertable("tbody")
        for item in playerlist("tbody > tr"):
            name = PyQuery(item)(".hide-for-small a.spielprofil_tooltip").text()
            link = PyQuery(item)(".hide-for-small a.spielprofil_tooltip").attr("href")
            link = "http://www.transfermarkt.ch" + link
            f = requests.get(link, headers=headers)
            playerpage = f.content
            playerpage = PyQuery(playerpage.decode("utf8"))
            clubname = playerpage(".dataZusatzDaten .hauptpunkt .vereinprofil_tooltip").text()
            league = playerpage(".dataZusatzDaten .mediumpunkt a").text()

            data_items = playerpage(".dataContent p")
            player_props = dict(
                [
                    (k.text(), v.text())
                    for k, v in zip(data_items(".dataItem").items(), data_items(".dataValue").items())
                ]
            )

            img_src = playerpage(".dataBild img").attr("src")
            img = requests.get(img_src, headers=headers).content
            try:
                im = Image.open(StringIO.StringIO(img))
                im.verify()
            except Exception:
                img = None

            # Conversions
            position = POSITION_MAPPING.get(player_props.get("Position:"))

            # Marktwert
            value_data = playerpage(".dataMarktwert").text()
            value = value_data.split()[0]
            multiplier = MULTIPLIER_MAPPING.get(value_data.split()[1], 1)
            if "," in value:
                value = int(value.split(",")[0]) * multiplier + int(value.split(",")[1]) * multiplier * 0.01
            else:
                value = int(value) * multiplier

            size = player_props.get(u"Gr\xf6\xdfe:", "0.00").replace(",", ".")
            date_of_birth = date.fromtimestamp(
                time.mktime(time.strptime(player_props.get("Geb./Alter:").split()[0], "%d.%m.%Y"))
            )

            # Lookup player
            player = session.query(Player).filter(Player.name == name and Player.nation_id == nation.id_).first()
            # Create a new player if we didn't find one.
            if player is None:
                player = Player(name, position, nation.id_, event)
                session.add(player)
            # Set/update player properties
            player.original_name = player_props.get("Name im Heimatland:")
            player.date_of_birth = date_of_birth
            player.age = int(player_props.get("Geb./Alter:").split()[1].strip("()"))
            # player.foot = player_props.get(u'Fu\xdf:')
            player.value = value
            player.size = size
            player.club = clubname
            player.league = league
            player.image = img
开发者ID:4teamwork,项目名称:ftw.footballchallenge,代码行数:85,代码来源:playerimport.py


注:本文中的pyquery.PyQuery.decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。