Guidance Request (and a specific question)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eBob.com

    Guidance Request (and a specific question)

    I am wondering if JavaScript is a reasonable way to solve my problem. I
    have to snatch some info from a web page and build a report. Some of the
    info comes from the web page and some will be supplied by the end user.
    This process will be initiated by the end user clicking on a menu item in
    the IE (6.0) Tools menu. I will need to access the html of the web page and
    then solicit some input from the end user via some form or something
    similar. I know that's rather vague but does it seem feasible?

    Thus far I am trying to access the html of the page and it's been tough
    going. One of the bits of info I want to snatch from a web page is a
    telephone number, which, on one of the web sites, looks like this ...

    <table cellpadding='0' cellspacing='0' align='center'>
    <tr>
    <td align='center' class='class_20 ' >Telphone: <span class='class_23 '
    style="font-size:14px;font-weight:bold;">1 11-222-3333</span></td>
    </tr>
    </table>

    After reading the first few chapters in a JavaScript book and looking at
    some DOM reference material, I've, so far, got the following:

    <script type="text/javascript">
    var parentwin = external.menuAr guments;
    var doc = parentwin.docum ent;
    var x = doc.getElements ByTagName("td")
    alert(x.length + " td things")
    // alert(x[0].toString)
    for (whatever in x)
    { alert(whatever. nodeName)
    }
    </script>

    I've tried many, many things but I have been unable to find the text I am
    after - in this case "Telephone: " and the telephone number, "111-222-3333".
    The objects returned by getElementsByTa gName don't seem to have a toString
    method, which I had hoped would give me "<td ... </td>". I am currently
    trying to learn something about DOM "nodes" - but I am not at all sure that
    that will be the answer. So, the specific question I promised - how do I
    grab the strings "Telephone: " and "111-222-3333" from the html shown above.

    Thanks for whatever help, pointers, sympathy you are kind enough to provide.
    Bob





  • Martin Honnen

    #2
    Re: Guidance Request (and a specific question)

    eBob.com wrote:
    <table cellpadding='0' cellspacing='0' align='center'>
    <tr>
    <td align='center' class='class_20 ' >Telphone: <span class='class_23 '
    style="font-size:14px;font-weight:bold;">1 11-222-3333</span></td>
    </tr>
    </table>
    >
    After reading the first few chapters in a JavaScript book and looking at
    some DOM reference material, I've, so far, got the following:
    >
    <script type="text/javascript">
    var parentwin = external.menuAr guments;
    var doc = parentwin.docum ent;
    I've tried many, many things but I have been unable to find the text I am
    after - in this case "Telephone: " and the telephone number, "111-222-3333".
    The objects returned by getElementsByTa gName don't seem to have a toString
    method, which I had hoped would give me "<td ... </td>".
    With IE's HTML DOM the element nodes have properties innerText,
    innerHTML and outerHTML. Also table elements objects have a rows
    collection and rows have a cells collection. That way
    var table1 = doc.getElements ByTagName('tabl e')[0];
    var cell1 = table1.rows[0].cells[0];
    var text = cell1.innerText ;
    That cell above has a couple of child nodes, its firstChild is a text
    node with the text "Telphone: ", its second child is a span element so
    you could use
    var text1 = cell1.firstChil d.nodeValue;
    and
    var text2 = cell1.childNode s[1].innerText;
    to have text1 hold the text "Telphone: " and text2 hold the text
    "111-222-3333"

    --

    Martin Honnen

    Comment

    • eBob.com

      #3
      Re: Guidance Request (and a specific question) - Thanks ...


      "Martin Honnen" <mahotrash@yaho o.dewrote in message
      news:482dae26$0 $7538$9b4e6d93@ newsspool1.arco r-online.net...
      eBob.com wrote:
      >
      ><table cellpadding='0' cellspacing='0' align='center'>
      ><tr>
      > <td align='center' class='class_20 ' >Telphone: <span class='class_23 '
      >style="font-size:14px;font-weight:bold;">1 11-222-3333</span></td>
      ></tr>
      ></table>
      >>
      >After reading the first few chapters in a JavaScript book and looking at
      >some DOM reference material, I've, so far, got the following:
      >>
      ><script type="text/javascript">
      >var parentwin = external.menuAr guments;
      >var doc = parentwin.docum ent;
      >
      >
      >I've tried many, many things but I have been unable to find the text I am
      >after - in this case "Telephone: " and the telephone number,
      >"111-222-3333". The objects returned by getElementsByTa gName don't seem
      >to have a toString method, which I had hoped would give me "<td ...
      ></td>".
      >
      With IE's HTML DOM the element nodes have properties innerText, innerHTML
      and outerHTML. Also table elements objects have a rows collection and rows
      have a cells collection. That way
      var table1 = doc.getElements ByTagName('tabl e')[0];
      var cell1 = table1.rows[0].cells[0];
      var text = cell1.innerText ;
      That cell above has a couple of child nodes, its firstChild is a text node
      with the text "Telphone: ", its second child is a span element so you
      could use
      var text1 = cell1.firstChil d.nodeValue;
      and
      var text2 = cell1.childNode s[1].innerText;
      to have text1 hold the text "Telphone: " and text2 hold the text
      "111-222-3333"
      >
      --
      >
      Martin Honnen
      http://JavaScript.FAQTs.com/
      Thank you VERY much Martin! That's exactly what I needed. Bob


      Comment

      Working...