package com.qst.atbtmusic.spider;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import com.qst.atbtmusic.entity.SongMsg;
import com.qst.atbtmusic.mapper.SingerMapper;
import com.qst.atbtmusic.mapper.SongMapper;
import com.qst.atbtmusic.mapper.UserMapper;
import com.qst.atbtmusic.pojo.Singer;
import com.qst.atbtmusic.pojo.SingerIdList;
import com.qst.atbtmusic.pojo.Song;
import com.qst.atbtmusic.pojo.User;
import com.qst.atbtmusic.util.HttpClientUtil;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping("/qq")
public class NetMusicGrab {
private final static Log logger = LogFactory.getLog(NetMusicGrab.class);
@Autowired
private UserMapper userMapper;
@Autowired
SingerMapper singerMapper;
@Autowired
SongMapper songMapper;
//获取歌手每首歌的id
public static List<String> getSongIdList(String url,String charest) {
List<String> songId = new ArrayList<String>();//存储歌曲id信息
List<String> songWord = new ArrayList<String>();//存储歌曲歌词id的信息
Document document = getDocument(url, charest);
// System.out.println("document: "+document);
if(document!=null){
//Elements elements = document.select(".m-sgerlist");//所有的歌手信息
//获取歌手的歌曲信息
Elements elements = document.select(".f-cb").select("a");//获取歌曲的id
for(int i=0;i<elements.size();i++) {
String song_id = elements.get(i).attr("href");//歌曲id
if(song_id.contains("song?id")) {
System.out.println("歌曲id:"+song_id);
String songword_id = song_id.substring(9);//将链接切割
songWord.add("http://music.163.com/api/song/media?id="+songword_id);
songId.add(songword_id);
}
}
return songId;
}
return null;
}
//获取歌手每首歌的歌词
public static String getSongWordList(String url,String charest) {
String musicWord = new String();
Document document = getDocument(url, charest);
if(document!=null){
Elements elements = document.select("body");//所有的歌曲信息
//获取歌曲信息
System.out.println("json数据如下");
String resJson = elements.text();
logger.info(resJson);
Gson gson = new Gson();
JsonParser jsonParser = new JsonParser();//将获取的歌词转成字符串list
JsonObject jsonElement = jsonParser.parse(resJson).getAsJsonObject();
String word = gson.fromJson(jsonElement, Words.class).toString();
//System.out.println(word);//输出歌词
// musicWord.add(word);
return word;
}
return null;
}
public List<Song> getSongList(String url, String charest) {
Singer artist = new Singer();//存储歌手信息
Document document = getDocument(url, charest);
if (document != null) {
Elements elements = document.select("#song-list-pre-data");//所有的歌曲信息
//获取歌手信息
Elements elements1 = document.select("h2");//获取歌手的名字,歌手所在标签
String singer_name = elements1.text();//获取歌手的名字
Elements elements2 = document.select("img");//获取歌手的图片地址
String singer_img = elements2.attr("src");
artist.setSingerName(singer_name);
artist.setSingerImg(singer_img);//将歌手信息存储到对象中
//获取歌曲信息
System.out.println("json数据如下");
String resJson = elements.text();
logger.info(resJson);
Gson gson = new Gson();
Type listType = new TypeToken<List<SongMsg>>() {
}.getType();
if (resJson != null && !resJson.contains("html")) ;
List<Song> songList = new ArrayList<Song>();
List<SongMsg> msgList1 = gson.fromJson(resJson, listType);
for (SongMsg sm : msgList1) {
Song song = new Song();//封装歌曲信息
song.setSongAddress("http://music.163.com/song/media/outer/url?id=" + sm.getId());
song.setSongImg(sm.getAlbum().getPicUrl());
song.setSongName(sm.getName());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
//System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
song.setSongTime(df.format(new Date()));
//封装对象
songList.add(song);
}
//uploadMP3(msgList);
return songList;
}
return null;
}
public static Document getDocument(String url, String charest) {
List<Header> headerList = new ArrayList<Header>();
String[] ua = {"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36 OPR/37.0.2178.32",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586",
"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 BIDUBrowser/8.3 Safari/537.36",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36 Core/1.47.277.400 QQBrowser/9.4.7658.400",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 UBrowser/5.6.12150.8 Safari/537.36",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 TheWorld 7",
"Mozilla/5.0 (Windows NT 6.1; W…) Gecko/20100101 Firefox/60.0"};
headerList.add(new BasicHeader("Host"
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot+Mybatis的音乐网站,基于mahout的协同过滤算法进行歌曲推荐,支付宝沙箱模拟支付.zip
共78个文件
java:50个
html:20个
properties:2个
需积分: 5 0 下载量 101 浏览量
2024-05-19
21:56:12
上传
评论
收藏 211KB ZIP 举报
温馨提示
协同过滤算法(Collaborative Filtering)是一种经典的推荐算法,其基本原理是“协同大家的反馈、评价和意见,一起对海量的信息进行过滤,从中筛选出用户可能感兴趣的信息”。它主要依赖于用户和物品之间的行为关系进行推荐。 协同过滤算法主要分为两类: 基于物品的协同过滤算法:给用户推荐与他之前喜欢的物品相似的物品。 基于用户的协同过滤算法:给用户推荐与他兴趣相似的用户喜欢的物品。 协同过滤算法的优点包括: 无需事先对商品或用户进行分类或标注,适用于各种类型的数据。 算法简单易懂,容易实现和部署。 推荐结果准确性较高,能够为用户提供个性化的推荐服务。 然而,协同过滤算法也存在一些缺点: 对数据量和数据质量要求较高,需要大量的历史数据和较高的数据质量。 容易受到“冷启动”问题的影响,即对新用户或新商品的推荐效果较差。 存在“同质化”问题,即推荐结果容易出现重复或相似的情况。 协同过滤算法在多个场景中有广泛的应用,如电商推荐系统、社交网络推荐和视频推荐系统等。在这些场景中,协同过滤算法可以根据用户的历史行为数据,推荐与用户兴趣相似的商品、用户或内容,从而提高用户的购买转化率、活跃度和社交体验。 未来,协同过滤算法的发展方向可能是结合其他推荐算法形成混合推荐系统,以充分发挥各算法的优势。
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot+Mybatis的音乐网站,基于mahout的协同过滤算法进行歌曲推荐,支付宝沙箱模拟支付.zip (78个子文件)
content
mvnw.cmd 6KB
pom.xml 7KB
src
test
java
com
qst
atbtmusic
AtbtmusicApplicationTests.java 346B
main
resources
application.properties 1B
templates
singer.html 25KB
register.html 4KB
allFunction822.html 139KB
index-cover-init.html 1KB
pay.html 185B
my-songlist.html 8KB
index-pageIndex2.html 58KB
bottom-music-control.html 2KB
model-player.html 29KB
search.html 14KB
index-pageIndex.html 38KB
allFunction821.html 237KB
flex.html 1KB
main-user.html 24KB
tryScroll.html 6KB
login.html 2KB
index.html 5KB
allFunction1.html 206KB
allFunction.html 137KB
music-nav.html 2KB
application.yml 497B
java
com
qst
atbtmusic
spider
Words.java 293B
NetMusicGrab.java 15KB
mapper
SongListMapper.java 2KB
UserMapper.java 2KB
SongMapper.java 4KB
VideoMapper.java 1KB
SingerMapper.java 978B
CommentMapper.java 701B
servlet
MyServlet.java 619B
controller
AlipayController.java 3KB
VideoController.java 2KB
SongController.java 6KB
UserController.java 7KB
MainController.java 298B
SingerController.java 2KB
SongListController.java 3KB
CommentController.java 519B
JsoupController.java 3KB
pojo
SongAndSinger.java 3KB
SongList.java 2KB
Comment.java 967B
Video.java 2KB
Attention.java 415B
Satisfaction.java 806B
SingerIdList.java 378B
Song.java 2KB
User.java 2KB
Singer.java 1KB
component
LoginHandlerInterceptor.java 1KB
filter
MyFilter.java 564B
email
Emailcheck.java 5KB
entity
Album.java 365B
SongMsg.java 872B
Song.java 2KB
Artists.java 1KB
method
UserCFDemo.java 4KB
SaveFile.java 2KB
JsoupWorm.java 3KB
listener
MyListener.java 525B
util
FileUtil.java 1KB
HttpClientUtil.java 1KB
AtbtmusicApplication.java 1KB
config
MyMvcConfig.java 1KB
AlipayConfig.java 5KB
DruidConfig.java 2KB
MyServerConfig.java 2KB
MyWebAppConfigurer.java 3KB
MyBatisConfig.java 588B
.mvn
wrapper
maven-wrapper.properties 116B
maven-wrapper.jar 47KB
MavenWrapperDownloader.java 5KB
mvnw 9KB
.gitignore 333B
共 78 条
- 1
资源评论
生瓜蛋子
- 粉丝: 3824
- 资源: 5235
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功