gpt4 book ai didi

java - Jsoup 获取隐藏邮件

转载 作者:行者123 更新时间:2023-11-29 05:39:06 28 4
gpt4 key购买 nike

我正在解析电子邮件数据的页面。我如何获得隐藏的电子邮件 - 这是使用 JavaScript 生成的。这是我正在解析的页面如果您查看 html 源代码(使用 Firebug 或其他工具),您会发现它是在名为 sobi2Details_field_email 的 div 中生成的链接标记,并设置为 display:none 。这是我现在的代码,但问题出在电子邮件上

 doc = Jsoup.connect(strLine).get();
Element e5=doc.getElementById("sobi2Details_field_email");

if(e5!=null)
{
emaildata=e5.child(1).absUrl("href").toString();

}
System.out.println (emaildata);

最佳答案

您需要执行几个步骤,因为 Jsoup 不允许您执行 JavaScript。我对其进行了逆向工程,结果如下:

public static void main(final String[] args) throws IOException
{
final String url = "http://poslovno.com/kategorije.html?sobi2Task=sobi2Details&catid=71&sobi2Id=20001";
final Document doc = Jsoup.connect(url).get();
final Element e5 = doc.getElementById("sobi2Details_field_email");

System.out.println("--- this is how we start");
System.out.println(e5 + "\n\n\n\n");

// remove the xml encoding
System.out.println("---Remove XML encoding\n");
String email = org.jsoup.parser.Parser.unescapeEntities(e5.toString(), false);
System.out.println(email + "\n\n\n\n");

// remove the concatunation with ' + '
System.out.println("--- Remove concatunation (all: ' + ')");
email = email.replaceAll("' \\+ '", "");
System.out.println(email + "\n\n\n\n");

// extract the email address variables
System.out.println("--- Remove useless lines");
Matcher matcher = Pattern.compile("var addy.*var addy", Pattern.MULTILINE + Pattern.DOTALL).matcher(email);
matcher.find();

email = matcher.group();
System.out.println(email + "\n\n\n\n");

// get the to string enclosed by '' and concatunate
System.out.println("--- Extract the email address");
matcher = Pattern.compile("'(.*)'.*'(.*)'", Pattern.MULTILINE + Pattern.DOTALL).matcher(email);
matcher.find();

email = matcher.group(1) + matcher.group(2);
System.out.println(email);

}

关于java - Jsoup 获取隐藏邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18343773/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com