Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I will try to keep this short; I am trying to scrape information from exactly this website : http://eu.battle.net/wow/en/character/uldaman/Dus/statistic#21:152
That list includes an item "Highest 2 man personal rating" followed by a number. The number is what I'm looking for. Where exactly is the number stored and how can I obtain it?
Thanks in advance.
I am considering you are using jQuery:
$('#cat-152 dt').filter(function() { return $(this).text() == "Highest 2 man personal rating" }).siblings('dd').text()
var http = require('http');
var options = {
host: 'eu.battle.net',
path: '/wow/en/character/uldaman/Dus/statistic/152'
};
var count = 0;
http.get(options, function(res) {
var data = "";
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function(){
var d = data;
var payload = d.toString();
var finder = "<dt>Highest 2 man team rating</dt><dd>";
var indexOfHighest2Man = payload.indexOf(finder);
var indexOfClosingDD = payload.indexOf("</dd>", indexOfHighest2Man);
var count = payload.substr(indexOfHighest2Man, indexOfClosingDD - indexOfHighest2Man);
count = count.replace(/\s/g, "");
count = count.replace("<dt>Highest2manteamrating</dt><dd>", "");
//***************** Here is the answer *******************
console.log('Highest 2 man rating ',count);
//********************************************************
})
}).on('error', function(e) {
console.log('ERROR: ' + e.message);
});
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am learning nodeJS and I have this syntax error which I don't understand.
Can someone point out what is the syntax error, why I am getting it, and how do I bypass it?
var http = require('http');
var url = require('url');
var server = http.createServer(function(req,res) {
if (req.method == 'POST') {
return res.end("Only get requests");
}
var st = url.parse(req.url,true);
if (st.indexOf("parsetime") > -1) {
var time = st.substring(st.indexOf("iso"));
var date = new Date(time);
var out = '{
"hour":'+date.getHours()+',
"minute":'+date.getMinutes()+',
"second":'+date.getSeconds()+',
}';
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(out);
} else if (st.indexOf("unixtime") > -1) {
var time = st.substring(st.indexOf("iso"));
var date = new Date(time);
var out = "{
'unixtime':"+date.getTime()+"
}";
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(out);
} else {
return res.end("404");
}
});
server.listen(process.argv[2]);
The syntax error is on line 11 : " var out = '{ "
Remove the single quotes from here:
var out = '{
"hour":'+date.getHours()+',
"minute":'+date.getMinutes()+',
"second":'+date.getSeconds()+',
}';
Change the above to:
var out = {
"hour": date.getHours(),
"minute": date.getMinutes(),
"second": date.getSeconds(),
};
Or if I may be mistaken for the string to contain a JSON object, you need to do declare the out that way and stringify using:
out = JSON.stringify(out);
The problem is that you tried to have a multi-line string, which you can't do like that in JavaScript. It is probably easier to do it like this:
var out = '{';
out+='"hour":'+date.getHours(),
out+='"minute":'+date.getMinutes(),
out+='"second":'+date.getSeconds()
out+='}';
Or, even easier, just define the object, then use JSON.stringify() to turn it into a string:
var outObj = {
hour:date.getHours(),
minute:date.getMinutes(),
second:date.getSeconds()
};
var obj=JSON.stringify(outObj);
This just defines a normal object, then turns it into JSON
Remove quotes
var out = {"hour":'+date.getHours()+',
"minute":'+date.getMinutes()+',
"second":'+date.getSeconds()+',
};
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need your help on my new project
I hate regular expressions and its rules but i must use it this project.
want do this replace
var aString = '[bkz:sample key]';
I want get into key variable 'sample key' value from this aString
var key,clean;
key = 'sample key';
clean = cleanChars(key);
// clean = sample_key
//my target
key
how can i do this?
thanks in advance
function extractKey(str) {
var match = (str || '').match(/^\[bkz:(.+)\]$/);
return match? match[1] : '';
}
extractKey('[bkz:sample key]'); //sample key
var aString = "[bkz:sample key]";
var regex = /^\[(.+)\:(.+)\]$/;
var matches = regex.exec(aString);
// "sample key" should now be in matches[2]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm new to query/javascript and having a problem with the following code to calculate a gross value and tax amount based
on the net amount the user enters. The user will enter a double amount and the gross and vat amounts are also defined as doubles.
Can anyone help? I get an error: "Uncaught SyntaxError: Unexpected number" when i try running the following code.
$('#netPayment').change(calcLowerVatRateAndGrossAmount);
/* $('#netPayment').change(function(){
calcLowerVatRateAndGrossAmount();
}); */
});
function calcVatRateAndGrossAmount(){
var netPayment = parseFloat($('#netPayment').val());
var vatAmount = 00.0;
var VatRate = 20.0;
var grossPayment = 0.00;
var totalPaymentAmount = 0.00;
if (netPayment !== '') {
vatAmount = (netPayment * VatRate) / 100;
grossPayment = (netPayment - vatAmount);
$('#vatAmount').val(parseFloat(vatAmount.data).toFixed(2));
$('#grossPayment').val(parseFloat(grossPayment.data).toFixed(2));
} else {
$('#vatAmount').val(vatAmount.amountNull);
$('#grossPayment').val(grossPayment.amountNull);
}
};
So you calculate a number here
vatAmount = (netPayment * VatRate) / 100;
And in here, you treat vatAmount as an object that has a key data
$('#vatAmount').val(parseFloat(vatAmount.data).toFixed(2));
You should just be using the variable. A simple test
console.log("variable itself: ", vatAmount);
console.log("key data: ", vatAmount.data);
So you would need to just do
$('#vatAmount').val(vatAmount.toFixed(2));
$('#grossPayment').val(grossPayment.toFixed(2));
You do the same thing with grossPayment and you reference some other property vatAmount.amountNull
$('#vatAmount').val(vatAmount.amountNull);
$('#grossPayment').val(grossPayment.amountNull);
should be
$('#vatAmount').val(""); //or any error message
$('#grossPayment').val("");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I need help in this code:
FB.api("/me/friends?fields=id,name,birthday,picture, link", dojo.hitch(this, function(response) {
var birthdays = response.data; //list of friend objects from facebook
var currentMonth = new Date().getMonth() + 1;
var upcoming = [];
dojo.forEach(birthdays, function(item) {
if (item.birthday) {
var bday = item.birthday;
//if the birthday is after today
if (currentMonth <= bday.substr(0, 2) * 1 && new Date().getDate() <= new Date(bday).getDate()) {
upcoming.push(item);
}
}
});
//set the year to current year because of birth years being different.
var year = new Date().getFullYear();
upcoming = upcoming.sort(function(a, b) {
return new Date(a.birthday).setYear(year) - new Date(b.birthday).setYear(year);
});
console.log(upcoming);//console log here, but do whatever you want with the sorted friends
}));
The app is about wishing upcoming people birthdays. This code is actually in the script tags in my index.html file. Included in the script tags is the fb.login etc that are needed to log into the Facebook. I'm confused in the above code. How could I call the above code so that individually a single persons name return. Then call his picture so it returns. Then the link etc so that the person could use it to wish his friend through this app on Facebook. This is because I want to use the upcoming persons birthday, link etc separately.
together
var parentEl = document.getElementById('id_of_your_html_element_where_you_want_show_users');
upcoming.forEach(function(user){
var el = document.createElement('div');
el.innerHTML = user.name;
parentEl.appendChild(el);
});
or separate
var parentEl = document.getElementById('id_of_your_html_element_where_you_want_show_users');
var user = upcoming[some_index];
var el = document.createElement('div');
el.innerHTML = user.name;
parentEl.appendChild(el);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Is there a JavaScript library or easily working with cookies?
vanilla javascript FTW
/*********************************************************
gets the value of a cookie
**********************************************************/
document.getCookie = function(sName)
{
sName = sName.toLowerCase();
var oCrumbles = document.cookie.split(';');
for(var i=0; i<oCrumbles.length;i++)
{
var oPair= oCrumbles[i].split('=');
var sKey = decodeURIComponent(oPair[0].trim().toLowerCase());
var sValue = oPair.length>1?oPair[1]:'';
if(sKey == sName)
return decodeURIComponent(sValue);
}
return '';
}
/*********************************************************
sets the value of a cookie
**********************************************************/
document.setCookie = function(sName,sValue)
{
var oDate = new Date();
oDate.setYear(oDate.getFullYear()+1);
var sCookie = encodeURIComponent(sName) + '=' + encodeURIComponent(sValue) + ';expires=' + oDate.toGMTString() + ';path=/';
document.cookie= sCookie;
}
/*********************************************************
removes the value of a cookie
**********************************************************/
document.clearCookie = function(sName)
{
setCookie(sName,'');
}