I Need Get url as a string from this code. Only i need
(http://ww3.mp3juices.com/download/5487/8789094/123735064/1d8bb8aa0352/(osthi)---kalasala-kalasala )
<td style="width:240px;min-width:240px" class="controls">
<a class="action_buttons cs download" href="http://yournewncsoft.info/v356?product_name=%28Osthi%29+-+Kalasala+Kalasala&product_title=MP3Juices+Download+Manager&installer_file_name=%28Osthi%29+-+Kalasala+Kalasala+-+%5BMP3Juices.com%5D&product_file_name=%28Osthi%29+-+Kalasala+Kalasala+-+%5BMP3Juices.com%5D.mp3&product_download_url=http%3A%2F%2Fww3.mp3juices.com%2Fdownload%2F5487%2F8789094%2F123735064%2F1d8bb8aa0352%2F%28osthi%29---kalasala-kalasala" name="dl2" onclick="javascript:_gaq.push(['_trackPageview','/download/manager']);">ev
<input type="hidden" name="files[1][adrl]" value="http://yournewncsoft.info/v356?product_name=%28Osthi%29+-+Kalasala+Kalasala&product_title=MP3Juices+Download+Manager&installer_file_name=%28Osthi%29+-+Kalasala+Kalasala+-+%5BMP3Juices.com%5D&product_file_name=%28Osthi%29+-+Kalasala+Kalasala+-+%5BMP3Juices.com%5D.mp3&product_download_url=http%3A%2F%2Fww3.mp3juices.com%2Fdownload%2F5487%2F8789094%2F123735064%2F1d8bb8aa0352%2F%28osthi%29---kalasala-kalasala"/>
<input type="hidden" name="files[1][url]" value="http://ww3.mp3juices.com/download/5487/8789094/123735064/1d8bb8aa0352/(osthi)---kalasala-kalasala"/>
<input type="hidden" name="files[1][len]" value="252"/>
<input type="hidden" name="files[1][song_id]" value="2"/>
<input type="hidden" name="files[1][hash]" value="41e78609200a6de8d86d25bae2b2a922"/>
<input type="hidden" name="files[1][filesize]" value="480.99999999999994"/>
<input type="hidden" name="files[1][bitrate]" value="160"/>
<a class="action_buttons cs listen" href="javascript:;" name="dll2">ev
</td>
My Jsoup Code is
for (Element divAudio : divs){
count_songs++;
String songTitle = divAudio.select(".song_title").text();
//String songURL = divAudio.select(".url").attr("href");
Element link = divAudio.select("input[name=files[1][url]]").first();
String songURL= link.attr("value");
String songDuration = divAudio.select(".size").text();
String songSize = divAudio.select(".bit").text();
result_list.add(new song_details(songTitle, songURL, songDuration, songSize));
}
Edited: ANSWER IS:
Element link = divAudio.select("input[name*=url").first();
String songURL= link.attr("value");
Element link = divAudio.select("input[name*=url").first();
String songURL= link.attr("value");
This code working fine
Related
I want to fetch sometitle and somelink from HTML code below for my android app ...
HELP ME :(
<div class="proper-list list-group page-cat-wrap">
<figure class="col-md-12 thumb-vertical">
<div class="col-xs-4 thumb-image">
<a href="/somelink.html" class="image-hover">
<img alt="SomeTag" src="/storage/images/100/2382.jpg">
</a>
</div>
<figcaption class="col-xs-8">
<h3>
<a href="/somelink.html">
SomeTitle
</a>
</h3>
<p>
<a href="/secondlink.html">
SomeText
</a>
</p>
</figcaption>
<div class="clearfix"></div>
<div class="mobile-only icon-right">
<a href="/somelink.html">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</a>
</div>
I heard of jsoup but won't able to get links with jsoup.
Jsoup is the best library to parse any of HTML content or document,
Here is the link and example,
http://jsoup.org/
Example
private void parsehtmlPage(){
File input = new File("/yourFolder/home.html");
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
Element elementId = doc.getElementById("elementId");
Elements ankerLinks = elementId.getElementsByTag("a");
for (Element link : ankerLinks) {
String linkHref = link.attr("href");
String linkText = link.text();
}
}
I'm going to check this value with the Android Webview After saving the values to the local storage on the Android browser.
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>HTML5</title>
<script>
window.onload = function(){
loadStorage();
document.querySelector("form").onsubmit = saveStorage;
};
function saveStorage(){
var saveId = document.getElementById("saveId").checked;
var userId = document.getElementById("userId").value;
if(saveId){
window.localStorage.setItem("userId", userId);
window.localStorage.setItem("userIdSaved", true);
}else{
window.localStorage.removeItem("userId");
window.localStorage.setItem("userIdSaved", false);
}
}
function loadStorage(){
var userId = window.localStorage.getItem("userId");
document.getElementById("userId").value = userId;
if(userId!=null){
document.getElementById("saveId").checked = true;
}
}
</script>
</head>
<body>
<h1>Login(Web Storage)</h1>
<form action="login.php" method="post">
<fieldset>
id: <input type="text" name="id" id="userId" autocomplete="off">
<input type="checkbox" id="saveId">Save ID<br>
pass: <input type="password"><br>
<input type="submit" value="login">
</fieldset>
</form>
</body>
</html>
However, if you run a webview not output the value stored in the Android browser.
Check the values by executing the Webview, but does not save local storage in
<html>
<head>
<meta charset="UTF-8">
<title>HTML5</title>
</head>
<?
$Id = $_POST['id'];
?>
<script>
window.onload = function(){
var userId = window.localStorage.getItem("userId");
alert(userId);
init();
};
function init(){
var list = document.getElementById( "list");
list.innerHTML = "";
for( var i = 0; i < localStorage.length ; i++){
var key = localStorage.key(i);
list.options[list.options.length] = new Option(localStorage[key],key);
}
}
</script>
<body>
<h1>Result</h1>
<p>Welcome to <?=$Id?> </p>
home<br/>
<select id = "list" size= "10"></ select>
<fieldset >
key : <input type = "text" id= "key"/>
value : <input type = "text" id= "value"/>
</fieldset >
</body>
</html>
To show the value stored in the Webview, how can I do?
I am not sure you can use web localStorage inside WebView. However you may store values in the application preferences. Implement corresponding methods in your custom Javascriptinterface. See https://stackoverflow.com/a/10389678/527759
This is my html
<script src="/ClientScripts/swfobject.js" language="javascript" type="text/javascript"> </script>
<div class="contentDetails">
<div id="ctl00_MainContentPlaceHolder_ContentDetailsBodyDivision" class="body">
<div align="justify">
<p align="center"><img width="500" height="352" alt="MVM315" src="/UserUpload/Image/1(825).jpg" /></p>
<p align="center"><img width="500" height="352" alt="MVM315" src="/UserUpload/Image/2(598).jpg" /></p>
How can i get {src="/UserUpload/Image/1(825).jpg"} with jsoup ?
I have this code but not working
Document doc = Jsoup.parse(html);
Elements mElements = doc.select("div[id^=ctl00_MainContentPlaceHolder_ContentDetailsBodyDivision]");
Result = mElements.get(0).tagName("img").toString();
try this:
Element imageElement = document.select("img").first();
String absoluteUrl = imageElement.absUrl("src"); //absolute URL on src
String srcValue = imageElement.attr("src"); // exact content value of the attribute.
More info here: http://jsoup.org/cookbook/extracting-data/working-with-urls
What about:
Element img = document.select("img").first()
String src = img.attr("src");
For more info see this: http://jsoup.org/cookbook/extracting-data/attributes-text-html
i am trying to call a jersey service from android
#POST
#Path("/share")
#Produces(MediaType.APPLICATION_JSON)
#Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response shareProgramVideo(#FormParam("from")Integer from, #FormParam("to")List<Integer> to,#FormParam("programIds")List<Integer> programIds)
the service works fine with html form
<html>
<head>
<title>REST with Forms</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<br />
<form method="post" action="../dataService/rest/secure/program/share">
from: <input type="text" name="from" id="from" /><br />
to 1: <input type="text" name="to" id="to" /><br />
to 2: <input type="text" name="to" id="to" /><br />
programIds 1: <input type="text" name="programIds" id="programIds" /><br />
programIds 2: <input type="text" name="programIds" id="programIds" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
i am using android and HttpRequest library (https://github.com/kevinsawicki/http-request)
but its give me 400 bad request error
List<Integer> programs = new ArrayList<Integer>();
programs.add(1);
programs.add(2);
List<Integer> to = new ArrayList<Integer>();
to.add(1);
to.add(2);
Map<String, Object> data = new HashMap<String, Object>();
data.put("from", 1);
data.put("to", to);
data.put("programIds", programs);
HttpRequest request = HttpRequest.post(url)
.basic(WebServiceConfig.ADMIN, WebServiceConfig.ADMIN_PSW).contentType("application/x-www-form-urlencoded")
.acceptJson().form(data);
if (request.created() || request.ok()) {
return true;
} else {
Log.e("CreateUserProgramTask",
"request.code()=" + request.code() + "request.body()="
+ request.body());
return false;
}
I don't know the library you are using but I think the problem could be in the way you're creating the 'programs' and 'to' params:
List<Integer> programs = new ArrayList<Integer>();
programs.add(1);
programs.add(2);
List<Integer> to = new ArrayList<Integer>();
to.add(1);
to.add(2);
Map<String, Object> data = new HashMap<String, Object>();
data.put("from", 1);
data.put("to", to);
data.put("programIds", programs);
It seems the library is simply doing a toString() call in the Lists, but I think you should serialize as:
programs = "program1,program2"
to = "to1,to2"
I think this is not what is beins writen in the data Map
I'm using WebView to browse pesopay.com and it works properly, except when I pressed the submit button. Using internet browsers like Google Chrome will show a pop up window, it confirms the information you filled. But in my Android WebView nothing happened when I pressed the submit button. I think because WebView is not enabled to display a pop up window.
Can anyone point me what is wrong?
Here is my activity:
public class PaymentActivity extends Activity {
String amount1;
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.payment);
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
amount1 = extras.getString("amount1");
}
WebView web = (WebView) findViewById(R.id.web1);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("javascript:window.onload = function(){setValue(\""+ amount1 +"\");};");
web.loadUrl("file:///android_asset/www/index.html");
}
}
My web page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
function setValue(amount1) {
myValue = amount1;
document.getElementById("amount").value = myValue;
}
</script>
<script type="text/javascript">
function rand ( n )
{
document.getElementById("orderRefId").value = ( Math.floor ( Math.random ( ) * n + 1 ) );
}
</script>
</head>
<body onLoad="rand(200000)">
<!--
Note: https://www.pesopay.com/b2c2/eng/payment/payForm.jsp for live payment URL
https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp for test payment URL
-->
<form method="POST" name="frmPayment" action="https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp">
<table>
<tbody>
<tr>
<td>Order Reference No. (your reference number for every transaction that has transpired):</td>
<td><input type="text" id="orderRefId" name="orderRef" value="Test-001"/></td>
</tr>
<tr>
<td>Amount:</td>
<td><input type="text" name="amount" id="amount" value=""/></td>
</tr>
<tr>
<td>Currency Code - "608" for Philippine Peso, "840" for US Dollar:</td>
<td><input type="text" name="currCode" value="608"/></td>
</tr>
<tr>
<td>Language:</td>
<td><input type="text" name="lang" value="E"/></td>
</tr>
<tr>
<td>Merchant ID (the merchant identification number that was issued to you - merchant IDs between test account and live account are not the same):</td>
<td><input type="text" name="merchantId" value="18056869"/></td>
</tr>
<tr>
<td>Redirect to a URL upon failed transaction:</td>
<td><input type="text" name="failUrl" value="http://www.yahoo.com?flag=failed"/></td>
</tr>
<tr>
<td>Redirect to a URL upon successful transaction:</td>
<td><input type="text" name="successUrl" value="http://www.google.com?flag=success"/></td>
</tr>
<tr>
<td>Redirect to a URL upon canceled transaction:</td>
<td><input type="text" name="cancelUrl" value="http://www.altavista.com?flag=cancel"/></td>
</tr>
<tr>
<td>Type of payment (normal sales or authorized i.e. hold payment):</td>
<td><input type="text" name="payType" value="N"/></td>
</tr>
<tr>
<td>Payment Method - Change to "ALL" for all the activated payment methods in the account, Change to "BancNet" for BancNet debit card payments only, Change to "GCASH" for GCash mobile payments only, Change to "CC" for credit card payments only:</td>
<td><input type="text" name="payMethod" value="ALL"/></td>
</tr>
<tr>
<td>Remark:</td>
<td><input type="text" name="remark" value="Asiapay Test"/></td>
</tr>
<!--<tr>
<td>Redirect:</td>
<td><input type="text" name="redirect" value="1"/></td>
</tr>-->
<tr>
<td></td>
</tr>
<input type="submit" value="Submit">
</tbody>
</table>
</form>
</body>
</html>
If i am getting right , you need to use JavaScriptInterface for calling JavaScript function from Android.
Check this link which may help you :
http://www.codeproject.com/Articles/392603/Android-addJavaScriptInterface
Or check some websettings :
http://developer.android.com/reference/android/webkit/WebSettings.html#setSupportMultipleWindows%28boolean
try to put this code in onCreate()
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
The function which is responsible for dialogs in Webview is onJsAlert of WebChromeClient.
Here is sample code
public class MyWebChromeClient extends WebChromeClient {
#Override
public boolean onJsAlert(WebView view, String url, String message, JsResult jsResult) {
// you can create your own dialog here or just return true for no pop up.
return true;
}
}
and add this to your webview:
MyWebChromeClient myWebChromeClient = new MyWebChromeClient();
webView.setWebChromeClient(myWebChromeClient);