ICONICO

Discussion Thread

Data Extractor

Message Thread

For WindowsData Extractor

Extract any data, including email addresses and URLs from your files and webpages.

Posted in the Data Extractor Forum.




Export to Excel & extract by classname

Hello Nico,

I have been having trouble exporting to excel. The export to excel button has to be pushed quite a few time to work and prompt that it has trouble linking with excel. It worked fine a few months ago. I have also tried this on a couple of machines. Is anyone else having this problem?

Also, from a previous post, you mentioned extracting text using the getElementbyID.

How can this be done byClassName?

Googling around it, I have tried using some functions written by others, but it doesn't seem to work, i.e.

function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; iarrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}

cheers
Phil
by Phil on Jun 17 2009 4:41pm Reply

Export to Excel & extract by classname

Hi Phil.

We have not had any reports of the Excel export running slowly as you describe. It could be your particular office installation, I'm honestly unsure how to advise.

getElementbyID is a native Javascript function. You should be able to copy and paste a function into your script and use it freely. Remember the function needs to appear before the call to use it, not after.

Take a look at this script for getting elements by class:
http://robertnyman.com/20...anno-2008/
by Nico Westerdale on Jun 17 2009 4:52pm Reply

Export to Excel & extract by classname

Hi Nico,

Is it as simple as pasting the function?

I keep getting a script error message


var getElementsByClassName = function (className, tag, elm){
if (document.getElementsByClassName) {
getElementsByClassName = function (className, tag, elm) {
elm = elm || document;
var elements = elm.getElementsByClassName(className),
nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
returnElements = [],
current;
for(var i=0, il=elements.length; iil; i+=1){
current = elements[i];
if(!nodeName || nodeName.test(current.nodeName)) {
returnElements.push(current);
}
}
return returnElements;
};
}
else if (document.evaluate) {
getElementsByClassName = function (className, tag, elm) {
tag = tag || "*";
elm = elm || document;
var classes = className.split(" "),
classesToCheck = "",
xhtmlNamespace = "http://www.w3.org/1999/xhtml",
namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
returnElements = [],
elements,
node;
for(var j=0, jl=classes.length; jjl; j+=1){
classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
}
try {
elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
}
catch (e) {
elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
}
while ((node = elements.iterateNext())) {
returnElements.push(node);
}
return returnElements;
};
}
else {
getElementsByClassName = function (className, tag, elm) {
tag = tag || "*";
elm = elm || document;
var classes = className.split(" "),
classesToCheck = [],
elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
current,
returnElements = [],
match;
for(var k=0, kl=classes.length; kkl; k+=1){
classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
}
for(var l=0, ll=elements.length; lll; l+=1){
current = elements[l];
match = false;
for(var m=0, ml=classesToCheck.length; mml; m+=1){
match = classesToCheck[m].test(current.className);
if (!match) {
break;
}
}
if (match) {
returnElements.push(current);
}
}
return returnElements;
};
}
return getElementsByClassName(className, tag, elm);
};

DataExtractor.SetColumns(3);
DataExtractor.AddHeader(1, 'title1');
DataExtractor.AddHeader(2, 'title2');
DataExtractor.AddHeader(3, 'title3');

var div1 = document.getElementById('ref_678371_l');
var div2 = document.getElementById('ref_678371_c');
var div3 = document.getElementsByClassName('content');

DataExtractor.StartNewResult();
DataExtractor.AddResult(1, div1.innerHTML);
DataExtractor.AddResult(2, div2.innerHTML);
DataExtractor.AddResult(3, div3.innerHTML);
by Phil on Jun 17 2009 5:25pm Reply

Export to Excel & extract by classname

Yes what you've done should work
by Nico Westerdale on Jun 17 2009 5:29pm Reply

Export to Excel & extract by classname

I get a message saying:
-----
Data Extractor Script Error:

TypeError -2146827850
Object doesn't support this property or method

Please check that your script is correct.
-----

I am testing it on this webpage
http://www.google.com/fin...=LON%3AAAS
by Phil on Jun 17 2009 5:46pm Reply

Export to Excel & extract by classname

Phil,

I'm sorry to be blunt but we really can't help debug scripts. I can point you in the right direction, but this is out of the bounds of a support request. I'd suggest copying and pasting the script into a simple HTML page and see if it runs in Internet Explorer, replacing the Data Extractor calls with alert() statements, and going from there.
by Nico Westerdale on Jun 17 2009 6:23pm Reply

Our Software Stores

IconicoAccurate Design and Development Software

BitsDuJourDiscount Deal Coupons for Windows and Mac Software Apps

Our Software Services

SoftwareMarketingResourceYou Wrote the Code, Now How do you Sell it?

IcoBlogOur Official Blog

© copyright 2004-2019 Iconico, Inc. Code & Design. All Rights Reserved. Terms & Conditions Privacy Policy Terms of Use