程序从glassdoor获取平均评论 [英] Program to fetch the average review from glassdoor
本文介绍了程序从glassdoor获取平均评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编写一个与 glassdoor 交互的java代码[ ^ ]并检查我公司的平均评分。我做了以下事情
- >创建了一个员工账号
- >请求一个令牌密钥
但是glassdoor似乎没有api给我公司的统计数据。有没有办法,我可以获得我的comapny的统计数据(如我公司发布的评论数量,平均评分)
Hi,
I need to write a java code which interacts with glassdoor[^] and checks out average rating of my company. I did following things
--> created an employee account
-->Requested for a token key
But glassdoor is not seeming to have an api to give me statistics of my company. Is there a way wherein i can get the stats of my comapny(like number of reviews posted for my company, average rating )
推荐答案
自己获得解决方案>
got the solution myself
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class glass {
public static void main(String []args) throws IOException{
ArrayList<string>good=new ArrayList<string>();
ArrayList<string>bad=new ArrayList<string>();
String a="//Glassdoor url of the company";
URL url=new URL(a);
URLConnection conn=url.openConnection();
BufferedReader br=new BufferedReader(newInputStreamReader(conn.getInputStream()));
String i;
String filename="D:/comment.txt";
String gfile="D:/pros.txt";
String bfile="D:/cons.txt";
File file=new File(filename);
File pro=new File(gfile);
File con=new File(bfile);
if(!file.exists()){
file.createNewFile();
}
if(!pro.exists()){
pro.createNewFile();
}
if(!con.exists()){
con.createNewFile();
}
FileWriter fw=new FileWriter(file);
BufferedWriter bw=new BufferedWriter(fw);
FileWriter fpros=new FileWriter(pro);
BufferedWriter bpros=new BufferedWriter(fpros);
FileWriter fcons=new FileWriter(con);
BufferedWriter bcon=new BufferedWriter(fcons);
while((i=br.readLine())!=null){
bw.write(br.readLine());
}
br.close();
bw.close();
FileReader fr=new FileReader(file);
StringBuffer sb=new StringBuffer();
BufferedReader br1=new BufferedReader(fr);
String input=null;
while((input=br1.readLine())!=null){
sb.append(input);
}
input=sb.toString();
String pros="<span class="\" data-term-type="\" data-term-id="\">(.*?)</span><br />";
String cons="<span class="\" data-term-type="\" data-term-id="\">(.*?)</span><br />";
Pattern pattern=Pattern.compile(pros);
Pattern p1=Pattern.compile(cons);
Matcher m1=pattern.matcher(input);
Matcher m2=p1.matcher(input);
while(m1.find()){
System.out.println(m1.group(2));
//good.add(m1.group(2));
}
/*while(m2.find()){
bad.add(m2.group(2));
}*/
System.out.println(good.size());
/*for(int j=0;j<good.size();j++){>
bpros.write("{");
bpros.write(good.get(j));
bpros.write("}");
}*/
/*for(int j=0;j<bad.size();j++){>
bcon.write("{");
bcon.write(bad.get(j));
bcon.write("}");
}
*/
System.out.println("completed");
}
}</string></string></string></string>
这篇关于程序从glassdoor获取平均评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文