Commit 9230722d by shenjinzhu

提交更新文件

parent e78fa26d
...@@ -196,8 +196,11 @@ ...@@ -196,8 +196,11 @@
<scope>provided</scope> <scope>provided</scope>
<version>7.0.47</version> <version>7.0.47</version>
</dependency> </dependency>
<dependency>
<groupId>com.zhiwei.pro</groupId>
<artifactId>getzhihudata</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
......
...@@ -30,6 +30,7 @@ import org.apache.poi.hssf.usermodel.HSSFRow; ...@@ -30,6 +30,7 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import com.zhiwei.entity.Zhihu;
import com.zhiwei.servlet.MainController; import com.zhiwei.servlet.MainController;
import com.zhiwei.util.Config; import com.zhiwei.util.Config;
import com.zw.entity.ExcelFile; import com.zw.entity.ExcelFile;
...@@ -326,7 +327,6 @@ public class ExcelReadAndWrite { ...@@ -326,7 +327,6 @@ public class ExcelReadAndWrite {
boolean b = true; boolean b = true;
int tip = 0; int tip = 0;
int now = 999; int now = 999;
int before = 0;
try { try {
Thread.sleep(1000 * 5); Thread.sleep(1000 * 5);
while (cut) {// cut=true,插队中 while (cut) {// cut=true,插队中
...@@ -528,8 +528,8 @@ public class ExcelReadAndWrite { ...@@ -528,8 +528,8 @@ public class ExcelReadAndWrite {
List<String> urls = new ArrayList<String>();// 写入url List<String> urls = new ArrayList<String>();// 写入url
for (Weixin l : list) { for (Weixin l : list) {
if (null != l.getUrl()) { if (null != l.getUrl()) {
if (l.getUrl().startsWith("https://mp.weixin.qq.com/s") if (l.getUrl().startsWith("https://mp.weixin.qq.com/s?src")
|| l.getUrl().startsWith("http://mp.weixin.qq.com/s")) { || l.getUrl().startsWith("http://mp.weixin.qq.com/s?src")) {
urls.add(l.getUrl()); urls.add(l.getUrl());
log.info(l); log.info(l);
} }
...@@ -612,4 +612,112 @@ public class ExcelReadAndWrite { ...@@ -612,4 +612,112 @@ public class ExcelReadAndWrite {
return m.findByid(id); return m.findByid(id);
} }
public static void writeZhihu(List<Zhihu> list, String mail) throws Exception {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String inurl = "C:\\Users\\Administrator\\Desktop/" + (int) (Math.random() * 99) + sdf.format(cal.getTime()) + ".xls";
File tempFile = new File(inurl);
// 若是文件不存在就创建新文件
if (!tempFile.exists()) {
tempFile.createNewFile();
}
WritableWorkbook workbook = Workbook.createWorkbook(tempFile);
WritableSheet sheet = workbook.createSheet("table1", 0);
// 一些临时变量,用于写到excel中
Label l = null;
// 标题格式
WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 14, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
WritableCellFormat titleFormat = new WritableCellFormat(titleFont);
titleFormat.setAlignment(Alignment.CENTRE);
// 正文字体
WritableFont detFont = new WritableFont(WritableFont.ARIAL, 13, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
WritableCellFormat detFormat = new WritableCellFormat(detFont);
detFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
// 财新小字
WritableFont detFont2 = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, Colour.WHITE);
WritableCellFormat detFormat2 = new WritableCellFormat(detFont2);
detFormat2.setBackground(Colour.BLUE_GREY);
WritableCellFormat detFormat3 = new WritableCellFormat(detFont2);
detFormat3.setBackground(Colour.BLUE_GREY);
detFormat3.setAlignment(Alignment.CENTRE);
WritableFont urlf = new WritableFont(WritableFont.ARIAL, 11, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, Colour.BLUE);
WritableCellFormat urlFormat = new WritableCellFormat(urlf);
urlFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
int seq = 0;
l = new Label(0, seq, "地址");
sheet.addCell(l);
l = new Label(1, seq, "标题");
sheet.addCell(l);
l = new Label(2, seq, "内容");
sheet.addCell(l);
l = new Label(3, seq, "回答者");
sheet.addCell(l);
l = new Label(4, seq, "回答时间");
sheet.addCell(l);
l = new Label(5, seq, "作者地址");
sheet.addCell(l);
l = new Label(6, seq, "点赞数");
sheet.addCell(l);
for (Zhihu w : list) {
seq++;
l = new Label(0, seq, w.getId());
sheet.addCell(l);
l = new Label(1, seq, w.getTitle());
sheet.addCell(l);
l = new Label(2, seq, w.getContent());
sheet.addCell(l);
l = new Label(3, seq, w.getAuthor());
sheet.addCell(l);
l = new Label(4, seq, w.getTime());
sheet.addCell(l);
l = new Label(5, seq, w.getAuthorUrl());
sheet.addCell(l);
l = new Label(6, seq, w.getPointLikeNumber());
sheet.addCell(l);
}
int column = 0;
sheet.setColumnView(column++, 20);
sheet.setColumnView(column++, 25);
sheet.setColumnView(column++, 25);
sheet.setColumnView(column++, 25);
sheet.setColumnView(column++, 30);
sheet.setColumnView(column++, 80);
sheet.setColumnView(column++, 90);
workbook.write();
workbook.close();
log.info("内容写入成功");
SendMailUtil.sendMessage(mail, inurl, "zhihu");
System.out.println("发送完成");
}
public static List<String> readExcel(String url) {
InputStream stream = null;
String str = null;
List<String> list = new ArrayList<>();
try {
stream = new FileInputStream(url);
Workbook rwb = Workbook.getWorkbook(stream);
Sheet sheet = rwb.getSheet(0);
for (int i = 1; i < sheet.getRows(); i++) {
Cell cell = null;
for (int j = 0; j < sheet.getColumns(); j++) {
cell = sheet.getCell(j, i);
str = cell.getContents();
if (sheet.getCell(j, 0).getContents().equals("链接")) {
list.add(str);
}
}
}
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
} }
...@@ -25,6 +25,7 @@ public class FileThread extends Thread{ ...@@ -25,6 +25,7 @@ public class FileThread extends Thread{
public void run(){ public void run(){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
while(true){ while(true){
System.out.println("执行");
Calendar c=Calendar.getInstance(); Calendar c=Calendar.getInstance();
if(c.get(Calendar.HOUR_OF_DAY)==1){ if(c.get(Calendar.HOUR_OF_DAY)==1){
c.add(Calendar.DATE, -7); c.add(Calendar.DATE, -7);
...@@ -49,11 +50,11 @@ public class FileThread extends Thread{ ...@@ -49,11 +50,11 @@ public class FileThread extends Thread{
e.printStackTrace(); e.printStackTrace();
} }
} }
try { // try {
Thread.sleep(1000*60*30); // Thread.sleep(1000*60*30);
} catch (InterruptedException e) { // } catch (InterruptedException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} }
} }
} }
...@@ -5,6 +5,8 @@ import java.io.FileInputStream; ...@@ -5,6 +5,8 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
...@@ -14,20 +16,22 @@ import org.apache.poi.ss.usermodel.Sheet; ...@@ -14,20 +16,22 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.usermodel.WorkbookFactory;
import com.zhiwei.servlet.MainController;
import com.zw.entity.Weixin; import com.zw.entity.Weixin;
public class ReaderExcel { public class ReaderExcel {
private final static Log log = LogFactory.getLog(ReaderExcel.class); private final static Log log = LogFactory.getLog(ReaderExcel.class);
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
for (Weixin w : getExcel("")) { for (String w : getZhUrls("C:\\Users\\Administrator\\Desktop/新闻源栏目.xlsx")) {
log.info(w); Matcher m=Pattern.compile("[\\S]+").matcher(w);
if(m.find()) {
System.out.println(m.group().replace("java.util.regex.Matcher[pattern=[\\S]+ region=0,3 lastmatch=", ""));
}
} }
} }
public static List<Weixin> getExcel(String url) throws IOException { public static List<Weixin> getExcel(String url) throws IOException {
// String url="C:/Users/Administrator/Desktop/jd.xls"; // String url="C:/Users/Administrator/Desktop/jd.xls";
List<Weixin> list = new ArrayList<>(); List<Weixin> list = new ArrayList<>();
Workbook book = null; Workbook book = null;
book = getExcelWorkbook(url); book = getExcelWorkbook(url);
...@@ -47,26 +51,26 @@ public class ReaderExcel { ...@@ -47,26 +51,26 @@ public class ReaderExcel {
cell.setCellType(Cell.CELL_TYPE_STRING); cell.setCellType(Cell.CELL_TYPE_STRING);
String str = cell.getStringCellValue(); String str = cell.getStringCellValue();
if (str != null) { if (str != null) {
if(sheet.getRow(0).getCell(j)==null){ if (sheet.getRow(0).getCell(j) == null) {
continue; continue;
} }
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("来源")) { if (sheet.getRow(0).getCell(j).getStringCellValue().equals("来源")) {
w.setSource(str== null ? "null" : str); w.setSource(str == null ? "null" : str);
} }
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("时间")) { if (sheet.getRow(0).getCell(j).getStringCellValue().equals("时间")) {
w.setTime(str == null ? "null" : str); w.setTime(str == null ? "null" : str);
} }
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("标题")) { if (sheet.getRow(0).getCell(j).getStringCellValue().equals("标题")) {
w.setTitle(str== null ? "null" : str); w.setTitle(str == null ? "null" : str);
} }
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("地址")) { if (sheet.getRow(0).getCell(j).getStringCellValue().equals("地址")) {
w.setUrl(str == null ? "null" : str); w.setUrl(str == null ? "null" : str);
} }
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("内容")) { if (sheet.getRow(0).getCell(j).getStringCellValue().equals("内容")) {
w.setConetent(str== null ? "null" : str); w.setConetent(str == null ? "null" : str);
} }
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("关键词")) { if (sheet.getRow(0).getCell(j).getStringCellValue().equals("关键词")) {
w.setKeyValue(str== null ? "null" : str); w.setKeyValue(str == null ? "null" : str);
} }
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("阅读数")) { if (sheet.getRow(0).getCell(j).getStringCellValue().equals("阅读数")) {
w.setRead(str == null ? "null" : str); w.setRead(str == null ? "null" : str);
...@@ -108,6 +112,38 @@ public class ReaderExcel { ...@@ -108,6 +112,38 @@ public class ReaderExcel {
return list; return list;
} }
public static List<String> getZhUrls(String url) throws IOException {
List<String> list = new ArrayList<>();
Workbook book = null;
book = getExcelWorkbook(url);
Sheet sheet = getSheetByNum(book, 0);
int lastRowNum = sheet.getLastRowNum();
log.info("last number is " + lastRowNum);
for (int i = 1; i <= lastRowNum; i++) {
Row row = null;
row = sheet.getRow(i);
if (row != null) {
int lastCellNum = row.getLastCellNum();
Cell cell = null;
for (int j = 0; j < lastCellNum; j++) {
cell = row.getCell(j);
if (cell != null) {
cell.setCellType(Cell.CELL_TYPE_STRING);
String str = cell.getStringCellValue();
if (str != null) {
if (sheet.getRow(0).getCell(j) == null) {
continue;
}
if (sheet.getRow(0).getCell(j).getStringCellValue().equals("链接")) {
list.add(str);
}
}
}
}
}
}
return list;
}
public static Sheet getSheetByNum(Workbook book, int number) { public static Sheet getSheetByNum(Workbook book, int number) {
Sheet sheet = null; Sheet sheet = null;
try { try {
......
...@@ -2,14 +2,21 @@ package com.zhiwei.servlet; ...@@ -2,14 +2,21 @@ package com.zhiwei.servlet;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector; import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -19,13 +26,15 @@ import org.apache.commons.logging.Log; ...@@ -19,13 +26,15 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.zhiwei.chendong.ExcelReadAndWrite; import com.zhiwei.chendong.ExcelReadAndWrite;
import com.zhiwei.chendong.ReaderExcel; import com.zhiwei.chendong.ReaderExcel;
import com.zhiwei.entity.Zhihu;
import com.zhiwei.util.Config; import com.zhiwei.util.Config;
import com.zw.entity.ExcelFile; import com.zhiwei.util.Craw;
import com.zw.entity.Excels; import com.zw.entity.Excels;
import com.zw.entity.Weixin; import com.zw.entity.Weixin;
...@@ -34,7 +43,9 @@ public class MainController { ...@@ -34,7 +43,9 @@ public class MainController {
private final static Log log = LogFactory.getLog(MainController.class); private final static Log log = LogFactory.getLog(MainController.class);
public static Vector<Excels> lists = new Vector<Excels>(); public static Vector<Excels> lists = new Vector<Excels>();
public static Map<String, Integer> map = new HashMap<String, Integer>();
public static Excels excel = null; public static Excels excel = null;
public static int finished = 0;
@RequestMapping("/scanExcel") @RequestMapping("/scanExcel")
public String mian() { public String mian() {
...@@ -69,39 +80,37 @@ public class MainController { ...@@ -69,39 +80,37 @@ public class MainController {
public void downLode(HttpServletRequest request, HttpServletResponse response) { public void downLode(HttpServletRequest request, HttpServletResponse response) {
System.out.println(ExcelReadAndWrite.findEf()); System.out.println(ExcelReadAndWrite.findEf());
try { try {
response.setContentType("text/plain;charset=utf-8"); response.setContentType("text/plain;charset=utf-8");
response.setHeader("Pragma", "No-cache"); response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache"); response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0); response.setDateHeader("Expires", 0);
response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Origin", "*");
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
// String jsonpCallback = request.getParameter("callback");// // String jsonpCallback = request.getParameter("callback");//
// 客户端请求参数 // 客户端请求参数
out.println(JSON.toJSONString(ExcelReadAndWrite.findEf()));// out.println(JSON.toJSONString(ExcelReadAndWrite.findEf()));//
// 返回jsonp格式数据 // 返回jsonp格式数据
out.flush(); out.flush();
out.close(); out.close();
System.out.println(lists.size()); System.out.println(lists.size());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@RequestMapping(value = "/downLodeFile") @RequestMapping(value = "/downLodeFile")
public void downFile(HttpServletRequest request, HttpServletResponse response,String id) { public void downFile(HttpServletRequest request, HttpServletResponse response, String id) {
System.out.println(ExcelReadAndWrite.findEf()); System.out.println(ExcelReadAndWrite.findEf());
try { try {
response.setContentType("application/msexcel;"); response.setContentType("application/msexcel;");
response.setHeader("Content-Disposition", response.setHeader("Content-Disposition",
new String(("attachment;filename=" + "downLode.xls").getBytes("GB2312"), "UTF-8")); new String(("attachment;filename=" + "downLode.xls").getBytes("GB2312"), "UTF-8"));
File f = new File(ExcelReadAndWrite.findById(id)); File f = new File(ExcelReadAndWrite.findById(id));
// File f = new File(targetFolder.getPath()+File.separator+fName);
FileInputStream in = new FileInputStream(f); FileInputStream in = new FileInputStream(f);
byte b[] = new byte[1024]; byte b[] = new byte[1024];
int i = 0; int i = 0;
ServletOutputStream out = response.getOutputStream(); ServletOutputStream out = response.getOutputStream();
while ((i = in.read(b)) != -1) { while ((i = in.read(b)) != -1) {
out.write(b, 0, i); out.write(b, 0, i);
} }
out.flush(); out.flush();
...@@ -149,7 +158,6 @@ public class MainController { ...@@ -149,7 +158,6 @@ public class MainController {
Map<String, Boolean> map = new HashMap<String, Boolean>(); Map<String, Boolean> map = new HashMap<String, Boolean>();
boolean b = false; boolean b = false;
if (ExcelReadAndWrite.cut) { if (ExcelReadAndWrite.cut) {
} else { } else {
if (id != null) { if (id != null) {
String msg = ExcelReadAndWrite.startCut(id); String msg = ExcelReadAndWrite.startCut(id);
...@@ -243,4 +251,72 @@ public class MainController { ...@@ -243,4 +251,72 @@ public class MainController {
return "error3"; return "error3";
} }
@RequestMapping(value = "/zhup", produces = "application/json;charset=utf-8")
public String getScan(String mail, MultipartFile file, String start, String end) {
String fileName = file.getOriginalFilename();
String path = "C:\\Users\\Administrator\\Desktop/" + "/" + fileName;
log.info(path);
File targetFile = new File(path);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
List<String> urls = new ArrayList<>();
try {
urls = ReaderExcel.getZhUrls(path);
} catch (IOException e1) {
e1.printStackTrace();
}
Craw any = new Craw();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
SocketAddress addr = new InetSocketAddress("120.237.55.23", 8888);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
List<Zhihu> list = any.getQuestionAndAnswerByUrl(urls, proxy, 50, sdf.parse(start), sdf.parse(end), "",
mail);
ExcelReadAndWrite.writeZhihu(list, mail);
} catch (Exception e) {
e.printStackTrace();
}
ExcelReadAndWrite.delete(path);
return "zhihu";
}
@RequestMapping(value = "/zhNum", produces = "application/json;charset=utf-8")
@ResponseBody
public String getzhNum() {
return JSON.toJSONString(map);
}
public static void main(String[] args) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date st = new Date();
st.setDate(st.getDate() - 2);
List<String> urls = new ArrayList<>();
urls.add("https://www.zhihu.com/question/268337678");
SocketAddress addr = new InetSocketAddress("120.237.55.23", 8888);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
Craw any = new Craw();
// urls = new ArrayList<>();
// try {
// urls = ReaderExcel.getZhUrls("C:\\Users\\Administrator\\Desktop/知乎(2).xlsx");
// } catch (IOException e1) {
// e1.printStackTrace();
// }
List<Zhihu> list = any.getQuestionAndAnswerByUrl(urls, null, 50, sdf.parse("2018-03-07 16:00"),
sdf.parse("2018-03-08 16:00"), "", "");
for (Zhihu l : list) {
System.out.println(l);
}
ExcelReadAndWrite.writeZhihu(list, "949131080@qq.com");
}
@RequestMapping("/zh")
public String zh() {
return "zhihu";
}
} }
package com.zhiwei.util;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.SocketAddress;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.jayway.jsonpath.JsonPath;
import com.zhiwei.entity.Zhihu;
import com.zhiwei.servlet.MainController;
public class Craw {
static List<String> ips = new ArrayList<>();
static int nums = 0;
static {
ips.add("80.211.190.76:3128");
ips.add("187.32.172.65:3128");
ips.add("80.211.162.17:8888");
ips.add("80.211.11.229:80");
}
public static void craw() {
}
public synchronized List<Zhihu> getQuestionAndAnswerByUrl(List<String> list, Proxy proxy, int num, Date start,
Date end, String cookie, String mail) {
List<Zhihu> zhList = new ArrayList<Zhihu>();
int nowRun = 1;
for (String ul : list) {
MainController.map.put(mail, nowRun++);
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
try {
int ns = 0;
String title = "";
try {
BufferedReader in_0 = null;
URL url_0;
String result_0 = "";
url_0 = new URL(ul);
URLConnection con = null;
// if (proxy == null) {
con = url_0.openConnection();
// } else {
Proxy p = new Proxy(Type.HTTP, new InetSocketAddress(ips.get(nums % ips.size()).split(":")[0],
Integer.valueOf(ips.get(nums % ips.size()).split(":")[1])));
nums++;
// con = url_0.openConnection(p);
// }
con.setConnectTimeout(6000);
con.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
con.setRequestProperty("Cookie", cookie);
con.setRequestProperty("authorization", "oauth c3cef7c66a1843f8b3a9e6a1e3160e20");
in_0 = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while ((line = in_0.readLine()) != null) {
result_0 += line + "\n";
}
Document doc = Jsoup.parse(result_0);
Element e = doc.select("title").first();
title = e.ownText();
} catch (Exception eee) {
System.out.println(eee.getMessage());
}
ul = ul.replace("question", "questions");
ul = ul.replace("http://www.zhihu.com", "").replace("https://www.zhihu.com", "");
int tip = 0;
while (true) {
int bean = zhList.size();
BufferedReader in = null;
URL url;
String result = "";
System.out.println(ul);
try {
url = new URL("https://www.zhihu.com/api/v4" + ul
+ "/answers?include=data%5B*%5D.is_normal%2Cadmin_closed_comment%2Creward_info%2Cis_collapsed%2Cannotation_action%2Cannotation_detail%2Ccollapse_reason%2Cis_sticky%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Ceditable_content%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Ccreated_time%2Cupdated_time%2Creview_info%2Cquestion%2Cexcerpt%2Crelationship.is_authorized%2Cis_author%2Cvoting%2Cis_thanked%2Cis_nothelp%2Cupvoted_followees%3Bdata%5B*%5D.mark_infos%5B*%5D.url%3Bdata%5B*%5D.author.follower_count%2Cbadge%5B%3F(type%3Dbest_answerer)%5D.topics&offset="
+ ns + "&limit=20&sort_by=created");
URLConnection conn = null;
// if (proxy == null) {
conn = url.openConnection();
// } else {
Proxy p = new Proxy(Type.HTTP, new InetSocketAddress(ips.get(nums % ips.size()).split(":")[0],
Integer.valueOf(ips.get(nums % ips.size()).split(":")[1])));
nums++;
// conn = url.openConnection(p);
// }
conn.setConnectTimeout(6000);
conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
conn.setRequestProperty("Cookie", cookie);
conn.setRequestProperty("X-Za-Experiment",
"ge3:ge3_10,ge2:ge2_1,search_section_style:loosen,android_pass_through_push:all,new_more:new,nwebQAGrowth:experiment,nweb_feed_ad:experiment,qaweb_related_readings_content_control:open,market_tab_banner:market_tab_banner_show,live_store:ls_a2_b1_c1_f1,qaweb_thumbnail_abtest:new,nweb_search:nweb_search_heifetz,recommend_ebook_ac:ebook_old,enable_vote_down_reason_menu:enable,show_video_upload_attention:true,is_office:false,enable_tts_play:post,new_question_diversion:true,recom_answer_rec:recom_answer_ratio,wechat_share_modal:wechat_share_modal_show,new_live_feed_mediacard:old,nweb_feed_ui:expand,search_hybrid_tabs:without-tabs,hybrid_zhmore_video:no,recommend_live_guess_like:live_guess_es,nweb_growth_people:default,qrcode_login:qrcode,is_show_unicom_free_entry:unicom_free_entry_off,new_mobile_column_appheader:new_header,android_db_comment_with_repin_record:open,feed_hybrid_topic_recom_button_icon:yes,android_db_recommend_action:open,zcm-lighting:zcm,android_db_feed_hash_tag_style:button,app_store_rate_dialog:close,recommend_question:rec_question_old,top_weight_search:new_top_search,default:None,recommendation_abtest:new,is_new_noti_panel:no,android_db_repin_selection:open,nweb_related_advert:default,android_profile_panel:panel_b,nweb_write_answer:experiment,recommend_live_detail:live_detail_no_rerank_v2");
conn.setRequestProperty("X-Req-SSL", "proto=TLSv1.2,sni=,cipher=ECDHE-RSA-AES256-GCM-SHA384");
conn.setRequestProperty("authorization", "oauth c3cef7c66a1843f8b3a9e6a1e3160e20");
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line + "\n";
}
List<Object> json = JsonPath.read(result, "$.data.*");
Calendar cal = Calendar.getInstance();
for (Object obj : json) {
Matcher m = Pattern.compile(", content=(.+),").matcher(obj.toString());
String content = "";
if (m.find()) {
content = m.group(1);
content = content.split(",")[0];
}
Matcher m2 = Pattern.compile(", id=(.+), voteup").matcher(obj.toString());
String id = "";
if (m2.find()) {
id = m2.group(1);
}
String name = "";
String userUrl = "";
Matcher m4 = Pattern.compile(", name=(.+), is_").matcher(obj.toString());
if (m4.find()) {
name = m4.group(1);
name = name.split(",")[0];
if (name.equals("匿名用户")) {
} else {
Matcher m5 = Pattern.compile("url_token=(.+),").matcher(obj.toString());
if (m5.find()) {
userUrl = m5.group(1);
userUrl = userUrl.split(",")[0];
}
}
}
Matcher m5 = Pattern.compile("url_token=(.+), id").matcher(obj.toString());
if (m5.find()) {
userUrl = m5.group(1);
userUrl = userUrl.split(",")[0];
}
String questionId = "";
Matcher m6 = Pattern.compile("tion, id=(.+), upda").matcher(obj.toString());
if (m6.find()) {
questionId = m6.group(1);
questionId = questionId.split(",")[0];
}
String time = "";
Matcher m7 = Pattern.compile("created_time=(.+), id").matcher(obj.toString());
if (m7.find()) {
time = m7.group(1);
time = time.split(",")[0];
}
String pointLikeNumber = "0";
Matcher mn = Pattern.compile("voteup_count=(.+), col").matcher(obj.toString());
if (mn.find()) {
pointLikeNumber = mn.group(1);
pointLikeNumber = pointLikeNumber.split(",")[0];
}
String idUrl = "https://www.zhihu.com/question/" + questionId + "/answer/" + id;
Zhihu zhihu = new Zhihu();
zhihu.setContent(content.replaceAll("<[\\S\\s]+?>", ""));
zhihu.setTitle(title);
zhihu.setId(idUrl);
zhihu.setAuthor(name);
zhihu.setAuthorUrl("https://www.zhihu.com/people/" + userUrl);
zhihu.setPointLikeNumber(pointLikeNumber);
Long timestamp = Long.valueOf(time) * 1000l;
String date = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA)
.format(new Date(timestamp));
zhihu.setTime(date);
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
if (sdf.parse(date).before(start) || end.before(sdf.parse(date))) {
cal.setTime(sdf.parse(date));
continue;
}
} catch (Exception e) {
e.printStackTrace();
}
zhList.add(zhihu);
}
// if (end.before(cal.getTime())) {
//
// } else {
if (zhList.size() == bean) {
break;
}
// }
ns += 20;
if (ns > num * 20) {
break;
}
} catch (Exception e) {
tip++;
if (tip > 3) {
break;
}
e.printStackTrace();
}
// Thread.sleep(500);
}
} catch (Exception e) {
e.printStackTrace();
}
}
MainController.map.remove(mail);
return zhList;
}
}
package com.zw.entity;
public class Zhi {
private String mail;
private Integer num;
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
@Override
public String toString() {
return "Zhi [mail=" + mail + ", num=" + num + "]";
}
}
...@@ -126,7 +126,7 @@ public class SendMailUtil { ...@@ -126,7 +126,7 @@ public class SendMailUtil {
SimpleDateFormat sfm = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat sfm = new SimpleDateFormat("yyyyMMdd");
String str = sfm.format(new Date()); String str = sfm.format(new Date());
// From: 发件人 // From: 发件人
message.setFrom(new InternetAddress(sendMail, "有新短消息:连接转完了", "UTF-8")); message.setFrom(new InternetAddress(sendMail, "有新短消息", "UTF-8"));
// To: 收件人(可以增加多个收件人、抄送、密送) // To: 收件人(可以增加多个收件人、抄送、密送)
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "UTF-8")); message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "UTF-8"));
// Subject: 邮件主题 // Subject: 邮件主题
......
...@@ -11,8 +11,15 @@ ...@@ -11,8 +11,15 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
"> ">
<!-- 开启注解处理器 -->
<context:annotation-config />
<!-- 开启组件自动扫描,扫描路径由base-package属性指定 -->
<context:component-scan base-package="com.zhiwei">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<context:property-placeholder
ignore-unresolvable="true" location="classpath:datasource.properties" />
<context:property-placeholder ignore-unresolvable="true" location="classpath:datasource.properties" />
</beans> </beans>
\ No newline at end of file
...@@ -10,5 +10,5 @@ dbName=TmpData ...@@ -10,5 +10,5 @@ dbName=TmpData
host=192.168.0.36 host=192.168.0.36
port=26017 port=26017
socketIp=192.168.0.243 socketIp=192.168.0.11
socketPort=10201 socketPort=10201
\ No newline at end of file
...@@ -88,15 +88,14 @@ h5 { ...@@ -88,15 +88,14 @@ h5 {
data = JSON.parse(data) data = JSON.parse(data)
d = data d = data
data.forEach((e, index) => { data.forEach((e, index) => {
let tr = `<tr class="TR"> tbody.append("<tr class='TR'>"
<td class="id">${e.site}</td> +"<td class='id'>"+e.site+"</td>"
<td>${e.mail}</td> +"<td>"+e.mail+"</td>"
<td>${e.surplusCount/12}</td> +"<td>"+e.surplusCount/12+"</td>"
<td>${e.startDate}</td> +"<td>"+e.startDate+"</td>"
<td>${e.state}</td> +"<td>"+e.state+"</td>"
<td>${e.surplusCount}</td> +"<td>"+e.surplusCount+"</td>"
</tr>` +"</td></tr>")
tbody.append(tr)
}) })
} }
}) })
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Table</title> <title>Table</title>
<link rel="stylesheet" <link rel="stylesheet"
href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
...@@ -81,14 +81,13 @@ body { ...@@ -81,14 +81,13 @@ body {
data = JSON.parse(data) data = JSON.parse(data)
d = data d = data
data.forEach((e, index) => { data.forEach((e, index) => {
let tr = `<tr class="TR"> tbody.append("<tr class='TR'>"
<td>${e.id}</td> +"<td>"+e.id+"</td>"
<td>${e.mail}</td> +"<td>"+e.mail+"</td>"
<td>${e.date}</td> +"<td>"+e.date+"</td>"
<td><a href='/change4weixin/downLodeFile?id=${e.id}'>下载</a></td> +"<td>"+e.state+"</td>"
</tr>` +"<td><a href='/change4weixin/downLodeFile?id="+e.id+"'>下载</a>"
+"</td></tr>")
tbody.append(tr)
}) })
} }
}) })
......
<!DOCTYPE html>
<html>
<head>
<title>Table</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<!-- <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> -->
<style>
body {
background-image: url("./2.jpg");
}
#timeCanvas {
position: absolute;
top: 3%;
right: 3%;
height: 30px;
width: 210px;
}
.table {
position: absolute;
left: 15%;
top: 7%;
width: 70%;
z-index: 100;
}
.table tr {
background-color: transparent !important;
}
.table tr td {
border-color: #000 !important;
}
</style>
</head>
<body>
<table class="table table-striped">
<thead>
<tr>
<td>编号</td>
<td>提交者</td>
<td>运行需要时间</td>
<td>开始时间</td>
<td>状态</td>
<td>当前剩余的条数</td>
</tr>
</thead>
<tbody class="data"></tbody>
</table>
<script>
$(function () {
var tbody = $('.data')
var d = []
function getData() {
$(tbody).empty();
d = []
$.ajax({
type: 'get',
datatype: 'json',
url: 'http://192.168.0.245:8080/change4weixin/show',
success: function (data) {
data = JSON.parse(data)
d = data
data.forEach((e, index) => {
tbody.append("<tr class='TR'>"
+"<td class='id'>"+e.id+"</td>"
+"<td>"+e.mail+"</td>"
+"<td>"+e.surplusCount/12+"</td>"
+"<td>"+e.startDate+"</td>"
+"<td>"+e.state+"</td>"
+"<td>"+e.surplusCount+"</td>"
+"</td></tr>")
})
}
})
}
// getData()
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<link rel="stylesheet"
href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function() {
var tbody = $('.init')
var d = []
function getData() {
$(tbody).empty();
d = []
$.ajax({
type : 'get',
datatype : 'json',
url : '/change4weixin/zhNum ',
success : function(data) {
console.log(data);
var d = JSON.stringify(data);
tbody.append("<tr class='TR'>" + "<td class='id'>" + d
+ "</td>" + "</tr>")
}
})
}
getData()
})
</script>
<style type="text/css">
body {
background-image: url("./2.jpg");
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
padding-top: 200px;
}
form {
width: 20%;
margin-right: 15%;
}
.form-group {
margin-top: 20px;
}
#submit:hover {
color: #66afe9;
}
.example-title {
font-size: 16px;
margin: 20px 0 10px;
font-weight: bold;
}
</style>
</head>
<body>
<h6>ks:1.01</h6>
<br/>
<div class="init"></div>
<form action="/change4weixin/zhup" enctype="multipart/form-data"
method="post">
<input type="file" name="file" />
<div class="form-group">
<label for="email">邮箱号</label> <input type="text" name="mail"
class="form-control" id="email">
</div>
<div class="form-group">
<label>起始时间</label> <input type="text" name="start" id="start" />
</div>
<div class="form-group">
<label>截止时间</label> <input type="text" name="end" id="end" />
</div>
<div class="form-group">
<input type="submit" value="提交" class="form-control" id="submit" />
</div>
</form>
<div class="example">
<div class="example-title">图片事例</div>
<img src="./example.jpg" alt="事例">
<div class="example-title">文件实例</div>
<img src="./example2.png" alt="事例">
</div>
</body>
</html>
...@@ -11,8 +11,15 @@ ...@@ -11,8 +11,15 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
"> ">
<!-- 开启注解处理器 -->
<context:annotation-config />
<!-- 开启组件自动扫描,扫描路径由base-package属性指定 -->
<context:component-scan base-package="com.zhiwei">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<context:property-placeholder
ignore-unresolvable="true" location="classpath:datasource.properties" />
<context:property-placeholder ignore-unresolvable="true" location="classpath:datasource.properties" />
</beans> </beans>
\ No newline at end of file
...@@ -10,5 +10,5 @@ dbName=TmpData ...@@ -10,5 +10,5 @@ dbName=TmpData
host=192.168.0.36 host=192.168.0.36
port=26017 port=26017
socketIp=192.168.0.243 socketIp=192.168.0.11
socketPort=10201 socketPort=10201
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment