403 Forbidden 是HTTP协议中的一个状态码(Status Code)。可以简单的理解为没有权限访问此站。
- /**
- * @方法名称: importWeather
- * @实现功能: 定时存入实时天气预报 TODO: 方法入参根据页面对象设置
- * @create by zyw at 2022-03-19 14:04:31
- **/
- public void importComment() {
- System.out.println("~~~~~~~~定时存入玉龙雪山美团评论~~~~~~~~~~");
- HttpURLConnection conn = null;
- BufferedReader reader = null;
- //使用免费api查询美团评论数据,请求数据时需要提交的参数
- Map
params = new HashMap(); - StringBuilder stringBuilder = new StringBuilder();
-
- try {
- //存储返回结果
- String strRead = null;
- //开始连接
- URL url = new URL(requestURL+offset);
-
- conn = (HttpURLConnection) url.openConnection();
- conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
- //使用Get方式请求数据
- conn.setRequestMethod("GET");
- conn.connect();
- //输入流获取返回数据
- InputStream is = conn.getInputStream();
- reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-
- while ((strRead = reader.readLine()) != null) {
- stringBuilder.append(strRead);
- }
- JSONObject jsonObject = JSON.parseObject(stringBuilder.toString());
- List
MeiTuanlist = JSONObject.parseArray(jsonObject.getJSONArray("comments").toString(), MeiTuanComment.class); -
- List
CommentList = new ArrayList<>(); - for (int i = 0; i < MeiTuanlist.size(); i++) {
- YlxsPublicOpinionData data = new YlxsPublicOpinionData();
- if (MeiTuanlist.get(i).getStar()==50){
- //好评
- data.setPjFl("好评");
- }else if (MeiTuanlist.get(i).getStar()<50&&MeiTuanlist.get(i).getStar()>20){
- //中评
- data.setPjFl("中评");
- }else {
- //差评
- data.setPjFl("差评");
- }
- data.setID(UUID.randomUUID().toString().replace("-", "").substring(0, 20));
- data.setPjDd("景区");
- data.setName("玉龙雪山");
- if (MeiTuanlist.get(i).getCommentTime()!=null){
- data.setPjTime(new Date(new Long(new Long(MeiTuanlist.get(i).getCommentTime().substring(0,10)) * 1000)));
- }
- data.setPjUser(MeiTuanlist.get(i).getUserName());
- data.setPjContent(removeNonBmpUnicodes(MeiTuanlist.get(i).getComment()));
- data.setZancnt(Integer.parseInt(MeiTuanlist.get(i).getZanCnt()));
- data.setReadcnt(Integer.parseInt(MeiTuanlist.get(i).getReadCnt()));
- data.setQuality("true".equals(MeiTuanlist.get(i).getQuality())?1:0);
- data.setAnonymous("true".equals(MeiTuanlist.get(i).getAnonymous())?1:0);
- data.setPjSource("美团");
- CommentList.add(data);
- }
- int p = ylxsPublicOpinionDataService.insertYlxsPublicOpinionDataList(CommentList);
-
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (conn != null) {
- conn.disconnect();
- }
- }
- }
-
- //去除表情
- public static String removeNonBmpUnicodes(String s) {
- return null == s ? null : s.replaceAll("[^\\u0000-\\uFFFF]", "");
- }