又要进入一个新的人生阶段了,为了响应国家号召,努力在造娃,现在的人给孩子起名都是各种讲究,这里给大家提供一个方式,即使用网上的一些名字的测算站点,获取名字的评分,限定评分多少的供自己选择,降低起名难度。
测评来源
姓名测试打分-免费测名字打分-宝宝起名打分-周易取名测名网 https://xmcs.buyiju.com/
在网上随意找的一个,如果有觉得其他的好的,可以推荐过来,一起了解一下怎么通过新的来源进行筛选评分~~
声明: 如果影响了上述网站的利益,我会尽快把该文章删除或者做其他处理,请及时留言告知。
实现思路
- 首先需要获取所有汉字,Java获取所有汉字实在是太简单了,一个for循环就出来了
for(char c='\u4e00';c<='\u9fa5';c++){}
根据UTF8编码,对所有汉字进行遍历,甚至都包括偏旁部首以及没见过的生僻字哦。 - 模拟浏览器进行一一获取名字测评的结果,对结果进行筛选就是了,通过分析页面,获取需要筛选的标签
document.getElementsByTag("font").first().text();
,剩下的就自由发挥了吧。 - 由于自己没有好好学习,生僻字太多了怎么办?贴心的给附加上拼音咋样?
Pinyin.toPinyin(c)
代码实现
package com.sammery.ops.tester.edge;
import com.github.promeg.pinyinhelper.Pinyin;
import lombok.SneakyThrows;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
import java.util.*;
public class Test {
static List<Map<String,String>> result = new ArrayList<>();
@SneakyThrows
public static void main(String[] args) {
for(char c='\u4e00';c<='\u9fa5';c++){
Thread.sleep(100);
String xs = "丰", mz = "百" + c;
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String host = "https://xmcs.buyiju.com/";
HttpPost postRequest = new HttpPost(host);
//设置请求头,将爬虫伪装成浏览器
postRequest.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
postRequest.setHeader("Accept-Language", "zh-CN,zh;q=0.9");
try {
// 建立请求参数
List<NameValuePair> list = new LinkedList<>();
BasicNameValuePair param1 = new BasicNameValuePair("xs", xs);
BasicNameValuePair param2 = new BasicNameValuePair("mz", mz);
BasicNameValuePair param3 = new BasicNameValuePair("action", "test");
list.add(param1);
list.add(param2);
list.add(param3);
// 使用URL实体转换工具
UrlEncodedFormEntity entityParam = new UrlEncodedFormEntity(list, "UTF-8");
postRequest.setEntity(entityParam);
response = httpClient.execute(postRequest);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity httpEntity = response.getEntity();
String html = EntityUtils.toString(httpEntity, "utf-8");
Document document = Jsoup.parse(html);
String re = document.getElementsByTag("font").first().text();
if (Float.parseFloat(re) > 98){
Map<String,String> map = new HashMap<>();
map.put(xs+mz+"[" + Pinyin.toPinyin(c) + "]",re);
System.out.println(xs + mz + "[" + Pinyin.toPinyin(c) + "]" + re);
result.add(map);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
HttpClientUtils.closeQuietly(response);
HttpClientUtils.closeQuietly(httpClient);
}
}
System.out.println(result);
}
}
对生僻字也添加了拼音处理,如此复制到文本文件里再进行筛选,缩小筛选范围,降低起名难度,你觉得怎么样呢?
评论区