[英]hyphen converts into comma in web-scraping
I am scraping data from page with help of JavaScript & displaying on fancybox popup.我在 JavaScript 的帮助下从页面中抓取数据并显示在fancybox 弹出窗口中。
var str = "$26.61 - Framed bulletin board offers a self-stick surface for quick and easy note positioning, repositioning, and removing.";
When I output it, however, I get this:但是,当我输出它时,我得到了这个:
$26.61 , Framed bulletin board offers a self,stick surface for quick and easy note positioning, repositioning, and removing.
Here is some javascript:这是一些javascript:
var pro_desc = $('meta[name=Description]').attr("content");
var shortDesc = $.trim(pro_desc).substring(0, 225);
var count1 = shortDesc.search(/$/i);
if(count1!=-1) {
var short_desc1 = shortDesc.replace("$", "");
var short_desc2 = short_desc1.split("-");
var desc1 = short_desc2;
} else {
alert('In Else Section---'+shortDesc);
}
var product_description = desc1;
alert(product_description);
Why does my output have ,
's instead of -
's?为什么我的输出有
,
而不是-
?
Why does my output have
,
's instead of-
's?为什么我的输出有
,
而不是-
?
You are splitting on hyphens:您正在拆分连字符:
var short_desc2 = short_desc1.split("-");
So short_desc2
is an array containing strings, each of which was separated from the other by a hyphen.所以
short_desc2
是一个包含字符串的数组,每个字符串之间用连字符分隔。 Example:例子:
'foo-bar'.split('-');
// returns the array ['foo', 'bar']
Now, when you alert
an array ( alert(product_description);
), ie convert it back to a string, the elements are concatenated with a comma in between:现在,当您
alert
数组( alert(product_description);
),即将其转换回字符串时,元素之间用逗号连接:
alert('foo-bar'.split('-'))
// alerts 'foo,bar'
// or
alert([1,2,3]);
// alerts '1,2,3'
It's the same as doing:这与执行相同:
alert(arr.join(','));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.