大数据实验室作业总结
import re
import requests
import json
url = ‘http://music.taihe.com/search’
singer = {
“key”:“周杰伦”
}
response = requests.get(url,params=singer)
html = response.text
#print(html)
#print(reponse)
sids = re.findall(r’data-playdata="(.+?)"’,html)
#print(sids)
id_list = re.findall(r’\d+’,sids[0])
#print(id_list)
for i in id_list:
api = “http://musicapi.taihe.com/v1/restserver/ting?method=baidu.ting.song.playAAC&format=jsonp&callback=jQuery17202628249451505169_1542286502046&songid=%s&from=web&_=1542286504081”%i
#print(api)
response = requests.get(api)
data =response.text
#print(data)
data1=re.findall(r"((.*))",data)[0]
#print(data1)
data2=json.loads(data1)
mp3_name=data2[‘songinfo’][‘title’]
mp3_url = data2[‘bitrate’][‘file_link’]
print(mp3_name,mp3_url)
mp3 = requests.get(mp3_url)
with open (“E:\zhoujielun %s mp3”% mp3_name,‘wb’) as f:
f.write(mp3.content)
这个是百度音乐爬虫的代码,这个其实实用性很大,可以爬取很多自己想要的资料
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
fig = plt.figure()
ax = fig.gca(projection=‘3d’)
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X2 + Y2)
Z = np.sin®
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter(’%.02f’))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
这个是用matplotlib.库做一个三维的图形,虽然自己做的的不是很好,但是也从代码中学到了很多东西
import turtle
def drawGap(): #绘制数码管间隔
turtle.penup()
turtle.fd(5)
def drawLine(draw): #绘制单段数码管
drawGap()
turtle.pendown() if draw else turtle.penup()
turtle.fd(60)
drawGap()
turtle.right(90)
def drawDigit(x): #根据数字绘制七段数码管
drawLine(True) if x in [2,3,4,5,6,8,9] else drawLine(False)
drawLine(True) if x in [0,1,3,4,5,6,7,8,9] else drawLine(False)
drawLine(True) if x in [0,2,3,5,6,8,9] else drawLine(False)
drawLine(True) if x in [0,2,6,8] else drawLine(False)
turtle.left(90)
drawLine(True) if x in [0,4,5,6,8,9] else drawLine(False)
drawLine(True) if x in [0,2,3,5,6,7,8,9] else drawLine(False)
drawLine(True) if x in [0,1,2,3,4,7,8,9] else drawLine(False)
turtle.left(180)
turtle.penup()
turtle.fd(30)
#运行主程序
turtle.setup(900, 500)#展开画板
turtle.penup()
turtle.fd(-350)
turtle.pensize(5)
a=open(r"C:\Users\24218\520.txt")#引用文件
b=a.readlines()
b=b[0].split()
for i in range(0,len(b)):
b[i]=int(b[i])
a.close()
for x in b : #画出5201314
drawDigit(x)
turtle.hideturtle()
turtle.done()
这个是七段数码管的代码
在这里插入代码片#include <stdio.h>
#include <malloc.h>
#define LEN sizeof(struct wyc)
struct wyc
{
long num;
float score;
struct wyc*next;
};
int n;
struct wyc * creat()
{
struct wyc *head,*p1,*p2;
n=0;
p1=p2=( struct wyc *)malloc(LEN);
scanf("%ld%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct wyc *)malloc(LEN);
scanf("%ld%f",&p1->num,&p1->score);
}
p2->next=NULL;
return head;
}
void print(struct wyc * head)
{
struct wyc *p;
printf("\nNow,These %d records are :\n",n);
p=head;
if(head!=NULL)
while(p!=NULL)
{printf("%ld %5.lf\n",p->num,p->score);
p=p->next;
}
}
int main()
{struct wyc *head;
head=creat();
print(head);
return 0;
}
`这个是建立链表的代码