python网易
㈠ 如何使用python爬取网易云音乐歌单内的歌曲
1首先在浏览器在打开网易云音乐的网页版,并点进一个歌单。
2.在浏览器的开发者工具审查该页面的元素(一般按f12可以弹出该工具),选择Network,之后选择doc可以简便地找到我们需要的元素。
注:以下两步第3,第4步主要是为了防止网站的反爬,经过这两步后,基本可以避开网站的反爬,所以如果你爬取的网站没有反爬的话,可以跳过这两步。
3.查看网页的请求方式--get请求
4.查看header
5.在Response中找到我们所需要的元素所在的标签位置(如:我们要爬取的是歌曲,既需要寻找歌曲的名字与其id信息,观察可以发现其中一首歌单中的歌名-moon在类名为“f-hide”的ul标签的li标签的a标签中) ~
㈡ python爬取网易云音乐的时候ip被封了,怎么办
用代理。有很多免费的代理IP,搜索一下就有了。
㈢ 用python的scrapy框架写的爬取网易新闻的爬虫,有些正则表达式不知道怎么写的大家帮帮忙~
新闻的爬虫,
㈣ 网易卡达python怎么导入pygame
没看懂你的意思,如果是导入pygame,先下载pip( pygame下载器),后安win加R键,输入CMD,输入代码pip install pygame后按回车。
㈤ python3 新手一枚,运用Python3.4.1爬网页,网易的机器学习网页,报Unicodedecodeerror,该网页是utf-8.
童鞋,网页不是utf-8编码的。
至此,完全显示正确。
㈥ python在运行程序时报错,网易查了一下没明白,求大神解答
第一行的引号不匹配,第二个引号要改成英文引号
㈦ python poplib 模块 连接gmail出错 试过163 就没问题 这是什么原因
给你一个发送邮件,接收邮件,并且根据邮件头计算邮件发送,接收时间差的公共代码
#!/usr/bin/envpython
#coding=utf-8
importsys
importtime
importpoplib
importsmtplib
fromdatetimeimportdatetime
importemail
fromemail.parserimportParser
fromemail.headerimportdecode_header
fromemail.utilsimportparseaddr
fromemail.mime.textimportMIMEText
importre
importpyodbc
defremove_values_from_list(the_list,val):
whilevalinthe_list:
the_list.remove(val)
#邮件发送函数
defsend_mail(mail_host,mail_user,mail_pass,mail_postfix,to_list,sub,content):
me=""+""+mail_user+"@"+mail_postfix+""
#printme
msg=MIMEText(content,_subtype='plain')
msg['Subject']=sub
msg['From']=me
msg['To']=";".join(to_list)#将收件人列表以‘;’分隔
try:
server=smtplib.SMTP()
server.connect(mail_host)#连接服务器
server.login(mail_user,mail_pass)#登录操作
server.sendmail(me,to_list,msg.as_string())
server.close()
returnTrue
exceptException,e:
#printe
returnFalse
returnFalse
#邮件接收函数
defaccpet_mail(accpet_host,accpet_user,accpet_pass):
mail_list=[]
#printaccpet_host
#print"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
try:
p=poplib.POP3(accpet_host)
p.user(accpet_user)
p.pass_(accpet_pass)
(mail_count,mail_total_size)=p.stat()#返回一个元组:(邮件数,邮件尺寸)
foriinrange(mail_count):
mail_map={}
#邮件从1开始读取,retr方法返回一个元组:(状态信息,邮件,邮件尺寸)
status_info,email_info,email_size=p.retr(str(i+1))
#printdecode_header(email.message_from_string(str(email_info)))[0][0]
#printemail.message_from_string(str(email_info))
message={}
last_email_item,append_flag="",True
#printstr(decode_header(email_info)[0][0])
remove_values_from_list(email_info,'')
forj,email_iteminenumerate(email_info):
ifj==len(email_info)-1:
message["Content"]=email_item
break
email_item_list="".join(email_item.split(" ")).split(":")
iflen(email_item_list)!=2:
ifappend_flag==True:
message[last_email_item]=message.get(last_email_item)+email_item_list[0]
#printemail_item_list[0]
else:
ifemail_item_list[0]inmessage:
append_flag=False
continue
message[email_item_list[0]]=email_item_list[1]
last_email_item=email_item_list[0]
if"Subject"notinmessageor"Content"notinmessage:
p.dele(str(i+1))
continue
#printi+1,message.get("Subject"),message.get("Content")
content_match_list=re.findall(r"Thesendingtime",message.get("Content"))
subject_match_list=re.findall(r"MAILVIEW",message.get("Subject"))
ifsubject_match_list==[]orcontent_match_list==[]:
p.dele(str(i+1))
#printi+1,message.get("Subject"),message.get("Content")
#print"2:"+str(email_info)
continue
#printstr(i+1)
content_list=message.get("Content").split("#")
send_list=content_list[0].split(":")
#print"send_time"+str(datetime.strptime(send_list[1],'%Y%m%d%H%M%S'))
#mail_map["send_time"]=str(datetime.strptime(send_list[1],'%Y%m%d%H%M%S'))
#mail_map["recive_time"]=str(datetime.strptime(message.get("Date"),'%a,%d%b%Y%H:%M:%S+0800'))
sr_list=content_list[1].split("@")
from_list=sr_list[0].split(":")
to_list=sr_list[1].split(":")
#printfrom_list[0]+":"+from_list[1]
mail_map[from_list[0]]=from_list[1]
#printto_list[0]+":"+to_list[1]
mail_map[to_list[0]]=to_list[1]
#print"recive_time:"+str(datetime.strptime(message.get("Date"),'%a,%d%b%Y%H:%M:%S+0800'))
#Mon,30Mar201514:20:58+0800'%a,%d%b%Y%H:%M:%S+0800'
#mail_map["send_time"]=str(datetime.strptime(message.get("Date"),'%a,%d%b%Y%H:%M:%S+0800'))
#从字符串读取信息-->解密邮件头-->字符串取[0][0]-->以" "分组-->取第一个-->替换字符串"Fromnobody"为空-->格式化为日期格式-->得到接收时间
#mail_map["recive_time"]=str(datetime.strptime(str(decode_header(email.message_from_string(str(email_info)))[0][0]).split(" ")[0].replace("Fromnobody",""),'%a%b%d%H:%M:%S%Y'))
mail_map["send_time"]=str(time.strftime("%Y-%m-%d%H:%M:%S",time.localtime(time.mktime(email.utils.parsedate(message.get('Date'))))))
receive_time_list=message.get('Received').split(";")
mail_map["recive_time"]=str(datetime.strptime(receive_time_list[len(receive_time_list)-1].replace("(CST)","").lstrip(),'%a,%d%b%Y%H:%M:%S+0800'))
#printmessage
#print"send_time:%s"%mail_map.get('send_time')
#print"recive_time:%s"%mail_map.get('recive_time')
#print"----------------------------------------------------------------"
mail_list.append(mail_map)
p.dele(str(i+1))
p.quit()
returnmail_list
exceptpoplib.error_proto,e:
#print"Loginfailed:",e
p.quit()
returnmail_list
#sys.exit(1)
returnmail_list
#运行当前文件时,执行sendmail和accpet_mail函数
if__name__=="__main__":
'''
mailto_list,mail_send_host=['[email protected]'],"smtp.gacfiatauto.com"
mail_send_user,mail_send_pass,mail_send_postfix="test","GACFiat1234","gacfiatauto.com"
NOW=datetime.now()
now_str=datetime.strftime(NOW,'%Y%m%d%H%M%S')
sub="MAILVIEW"+now_str
content="Thesendingtime:"+now_str+"#from_mail:JV@to_mail:126"
send_mail(mail_send_host,mail_send_user,mail_send_pass,mail_send_postfix,mailto_list,sub,content)
#accpet_host,accpet_user,accpet_pass='pop.126.com','gacfiat','fiat100?'
accpet_host,accpet_user,accpet_pass='pop3.gacfiatauto.com','test','GACFiat1234'
accpet_mail(accpet_host,accpet_user,accpet_pass)
'''
DB2_HOST='10.27.95.30'
DB2_PORT='50000'
DB2_DB='db2s'
DB2_USER='db2admin'
DB2_PWD='fiat100?'
dsn="driver={IBMDB2ODBCDRIVER};database=%s;hostname=%s;port=%s;protocol=tcpip;"%(DB2_DB,DB2_HOST,DB2_PORT)
conn=pyodbc.connect(dsn+"uid="+DB2_USER+";pwd="+DB2_PWD+";");
cursor=conn.cursor()
cursor.execute("select*fromkernel.mail_property")
row=cursor.fetchone()
property_list=[]
#1获取要发送和接收邮件的属性信息
whilerow:
(from_mail,from_protocol,from_address,from_host,auth_flag,from_port,from_user,from_password,to_mail,to_protocol,to_address,to_host,to_port,to_user,to_password,is_current,t2)=(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10],row[11],row[12],row[13],row[14],row[15],row[16])
row=cursor.fetchone()
ifis_current=="1":#andfrom_mail=='126'andto_mail=="JV":
property_list.append((from_mail,from_protocol,from_address,from_host,auth_flag,from_port,from_user,from_password,to_mail,to_protocol,to_address,to_host,to_port,to_user,to_password,is_current,t2))
cursor.close()
#2发送邮件
forpropertyinproperty_list:
(from_mail,from_protocol,from_address,from_host,auth_flag,from_port,from_user,from_password,to_mail,to_protocol,to_address,to_host,to_port,to_user,to_password,is_current,t2)=property
mailto_list=[to_address]
mail_send_host=from_host
mail_send_user=from_user
mail_send_pass=from_password
mail_send_postfix=from_host.replace(from_protocol+".","")
NOW=datetime.now()
now_str=datetime.strftime(NOW,'%Y%m%d%H%M%S')
sub="MAILVIEW"+now_str
content="Thesendingtime:"+now_str+"#from_mail:"+from_mail+"@to_mail:"+to_mail
#printmail_send_host
send_resp=send_mail(mail_send_host,mail_send_user,mail_send_pass,mail_send_postfix,mailto_list,sub,content)
ifsend_resp:#如果发送失败,再尝试发送一次
continue
else:
#print'sendfail,sendagain.'
send_mail(mail_send_host,mail_send_user,mail_send_pass,mail_send_postfix,mailto_list,sub,content)
#3接收邮件
forpropertyinproperty_list:
(from_mail,from_protocol,from_address,from_host,auth_flag,from_port,from_user,from_password,to_mail,to_protocol,to_address,to_host,to_port,to_user,to_password,is_current,t2)=property
accpet_host=to_host
accpet_user=to_user
accpet_pass=to_password
starttime=datetime.now()
#printaccpet_host
mail_list=accpet_mail(accpet_host,accpet_user,accpet_pass)
#4添加邮件记录信息到DB2数据库中
insert_sql="insertintokernel.mail_data(from_mail,send_time,to_mail,recive_time)values"
fori,mailinenumerate(mail_list):
from_mail,send_time,to_mail,recive_time=mail['from_mail'],mail['send_time'],mail['to_mail'],mail['recive_time']
#printsend_time,from_mail,to_mail,recive_time
insert_sql=insert_sql+"('%s',to_date('%s','yyyy-mm-ddhh24:mi:ss'),'%s',to_date('%s','yyyy-mm-ddhh24:mi:ss')),"%(from_mail,send_time,to_mail,recive_time)
ifi==len(mail_list)-1:
insert_sql=insert_sql[:len(insert_sql)-1]
endtime=datetime.now()
message='开始时间:%s,总共耗时:%ss'%(starttime,(endtime-starttime).seconds)
#printmessage
ifmail_list!=Noneandmail_list!=[]:
#printinsert_sql
cursor=conn.cursor()
cursor.execute(insert_sql)
cursor.commit()
cursor.close()
#sys.exit(1)
㈧ 网易云音乐python 怎么使用
### 键盘快捷键
J Down 下移
K Up 上移
H Back 后退
L Forword 前进
U Prev page 上一页
D Next page 下一页
F Search 快速搜索
[ Prev song 上一曲
] Next song 下一曲
Space Play/Pause 播放/暂停
M Menu 主菜单
P Present 当前播放列表
A Add 添加曲目到打碟
Z DJ list 打碟列表
S Star 添加到收藏
C Collection 收藏列表
R Remove 删除当前条目
Q Quit 退出
### 安装
$ pip install netease-musicbox
$ brew install mpg123
### 使用
$ musicbox
㈨ 如何用python通过163发送邮件
# 导入 smtplib 和 MIMEText
import smtplib
from email.mime.text import MIMEText
# 定义发送列表
mailto_list=["[email protected]","[email protected]"]
# 设置服务器名称、用户名、密码以及邮件后缀
mail_host = "smtp.126.com"
mail_user = "user"
mail_pass = "pass"
mail_postfix="126.com"
# 发送邮件函数
def send_mail(to_list, sub, context):
'''''
to_list: 发送给谁
sub: 主题
context: 内容
send_mail("[email protected]","sub","context")
'''
me = mail_user + "<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(context)
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
send_smtp = smtplib.SMTP()
send_smtp.connect(mail_host)
send_smtp.login(mail_user, mail_pass)
send_smtp.sendmail(me, to_list, msg.as_string())
send_smtp.close()
return True
except (Exception, e):
print(str(e))
return False
if __name__ == '__mian__':
if (True == send_mail(mailto_list,"subject","context")):
print ("测试成功") www.codesky.net
else:
print ("测试失败")
㈩ 小甲鱼大大把Python的视频在网易云课堂更新一下呗
支持小甲鱼,赞点鱼币回来下载 查看更多答案>>
希望采纳