Jsoup href+;将目标文本转换为字符串
对另一个问题的回答表明,最好在我的Android项目中使用JSoup来解析以下对web调用的响应:Jsoup href+;将目标文本转换为字符串,jsoup,Jsoup,对另一个问题的回答表明,最好在我的Android项目中使用JSoup来解析以下对web调用的响应: var OX_abced445 = ''; OX_abced445 += "<"+"a href=\'http://the.server.url/openx/www/delivery/ck.phpoaparams=2__bannerid=29__zoneid=3__cb=e3efa8b703__oadest=http%3A%2F%2Fsomesite.com\'target=\'_blank
var OX_abced445 = '';
OX_abced445 += "<"+"a href=\'http://the.server.url/openx/www/delivery/ck.phpoaparams=2__bannerid=29__zoneid=3__cb=e3efa8b703__oadest=http%3A%2F%2Fsomesite.com\'target=\'_blank\'>This is some sample text to test with!<"+"/a><"+"div id=\'beacon_e3efa8b703\'style=\'position: absolute; left: 0px; top: 0px; visibility:hidden;\'><"+"img src=\'http://the.server.url/openx/www/delivery/lg.php?bannerid=29&campaignid=23&zoneid=3&loc=1&cb=e3efa8b703\' width=\'0\'height=\'0\' alt=\'\' style=\'width: 0px; height: 0px;\' /><"+"/div>\n";
document.write(OX_abced445);
var OX_abced445='';
OX_abced445+=“这是一些要测试的示例文本!\n”;
文件编写(OX_abced445);
我需要从这个响应中提取两个位,并将它们存储在两个字符串中。我还知道,回复将始终采用上述格式。我需要href url,但不需要img src url,因此我想我应该查找
href=\'
和'
之间的所有内容。我还需要提取目标文本,即。这是一些要测试的示例文本封装在\u blank\'>
和
之间的代码>。我设置了JSoup并连接到URL,检索响应,但选择器语法有问题。如有任何建议,将不胜感激 对你的问题略作抽象,因为我不完全理解细节
如果html文档中只有一个超链接,则可以使用
Element link_el = doc.select("a").first();
String href_url = link_el.attr("href");
String target_text = link_el.text();
如果html文档中有许多链接,那么您可能希望使用getElementsByClass为包含类选择所需的位
相关元素=doc.getElementsByClass(“相关类名”).first();
元素链接选择(“a”).first()
当然,如果有很多链接,那么您需要在doc上进行迭代。选择(“a”)非常感谢您的帮助。由于我的noob代码中存在一些其他错误,我无法测试您的建议,但我很快就会测试出来。