+ Reply to Thread
Results 1 to 21 of 21

download and set table in excel from web that uses Java script

  1. #1
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    download and set table in excel from web that uses Java script

    Hi, I am trying to download a table from a website which is built by using Java script. Basically I knew the element ID of source code by using getelementbyID, but the table is stored in a few cells in a column (the rows of the table in the web should be at least 200). My question is how could I have the table format in excel just look like the one in the web? One uploaded file is an excel including both scenario. Another word file is the HTML source code.

    I am using
    Please Login or Register  to view this content.
    to download the table so far.

    Should you need any further information, please let me know. Many thanks
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: download and set table in excel from web that uses Java script

    I am working with this website (http://www.hkexnews.hk/sdw/search/search_sdw.asp).
    After I entered stock code, for example 00005, the page jumps to another, but with the same website (http://www.hkexnews.hk/sdw/search/search_sdw.asp) (I don't know if this is the result of JAVA script). What I am looking for is the table in the second page (i.e., after I entered the stock code). Please help
    English is not my first language

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: download and set table in excel from web that uses Java script


    Hi,

    as in your previous threads you already had 3 methods to download a web table,
    with IE just try Wait method (just see in VBA help !) until table is loaded …

  4. #4
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: download and set table in excel from web that uses Java script

    Marc L, did you take a look at this website (http://www.hkexnews.hk/sdw/search/search_sdw.asp)? I cannot apply the previous 3 methods to download a web table. I dont know if this is due to this website is using JAVA script.
    Based on my shallow understanding of VBA, I guess this time the problem has nothing to do with WAIT.

    Quote Originally Posted by Marc L View Post

    Hi,

    as in your previous threads you already had 3 methods to download a web table,
    with IE just try Wait method (just see in VBA help !) until table is loaded …

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: download and set table in excel from web that uses Java script


    If you know to use your web browser you can see the table data in the webpage code,
    so like your previous threads for the same web site …

  6. #6
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: download and set table in excel from web that uses Java script

    as I said in post #1, the web table data was downloaded into excel in a few cells in one column. I DID try to use methods I learned from previous threads to map the rows and columns of web table into array, but I cannot success.
    Please Login or Register  to view this content.
    this is what I used to try to map the rows and columns of the web table, but I found the rows.length is JUST 13 (I also attached a demonstration file in post#1 - refer to the first worksheet), but the rows of the web table should be >200. This is what I am facing now.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: download and set table in excel from web that uses Java script


    At this time your link doesn't work anymore (site problem)
    but when I inspected webpage it seemed that the table to load hadn't an ID !

    Edit : it's your post #4 link which is bad ! First Ok …

    So the data are in another table inside the table with ID …

    Maybe better is to use a clipboard (copy / paste) like I did in one of your previous post, could be done in IE too …
    Last edited by Marc L; 10-14-2014 at 04:55 AM.

  8. #8
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: download and set table in excel from web that uses Java script

    I am using below code to get the result in the first worksheet of attached demonstration file. As you see the red code, this is what I GUESS the ID for the table. (I am not sure because my vba skill is very insufficient, that's why I am seeking help now). If this is in "normal" HTML format (I dont know if I describe it correctly), I could apply the knowledge from previous threads. But they are seemingly using another format so that I cannot make use of the knowledge from previous threads.

    I hope you can understand my situation.
    What result I would like to achieve is like simply copy the web table and paste it into excel (just like the second worksheet of the attached demonstration file) so that each cell carries only one value.
    Thank you once again

    Please Login or Register  to view this content.
    Quote Originally Posted by Marc L View Post

    At this time your link doesn't work anymore (site problem)
    but when I inspected webpage it seemed that the table to load hadn't an ID !

    Edit : it's your second link which is bad ! First Ok …

    So the data are in another table inside the table with ID …

    Maybe better is to use a clipboard (copy / paste) like I did in one of your previous post, could be done in IE too …

  9. #9
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: download and set table in excel from web that uses Java script

    I had also thought if it is possible to search <TR> and <TD> within ie.document.getelementbyid("tbl_Result_inner") to map the rows and cols of the web table. But I cannot identify the numbers of <TR> and <TD> in ie.document.getelementbyid("tbl_Result_inner"). Feeling shy to ask too many questions here. Sorry

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: download and set table in excel from web that uses Java script


    The table ID "tbl_Result_inner" is not the table with data ! Just check with webbrowser inspector tool …

    From this ID, you could use getElementsByTagName("TABLE") to get a collection of tables within this table ID
    and check which element is the table you are looking for …

    But if you need also data above this table (starting with Detail of Market), easier is to use clipboard method.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: download and set table in excel from web that uses Java script


    I just saw in your code READYSTATE.READYSTATE_COMPLETE is not defined, could never work like this …
    Last edited by Marc L; 10-14-2014 at 06:36 AM. Reason: typo

  12. #12
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: download and set table in excel from web that uses Java script

    I can use getElementsByTagName("TABLE") (12) to see the table data, but the whole table is saved in one cell. Now I had 2 questions.

    1.) when run to the second code
    Please Login or Register  to view this content.
    "Run-time error '424': Object Required" happened

    2.) I checked with Locals Windows and found ie.document.getElementsByTagName("TABLE")(12) only got 1 row, how could I map the rows and cols of the web table?

    Quote Originally Posted by Marc L View Post

    The table ID "tbl_Result_inner" is not the table with data ! Just check with webbrowser inspector tool …

    From this ID, you could use getElementsByTagName("TABLE") to get a collection of tables within this table ID
    and check which element is the table you are looking for …

    But if you need also data above this table (starting with Detail of Market), easier is to use clipboard method.

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: download and set table in excel from web that uses Java script


    What's the value of READYSTATE.READYSTATE_COMPLETE in your code ?
    While not fixed, code will never work …
    It's why you get the error 424 : table does not exist 'cause the page is still loading !

  14. #14
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: download and set table in excel from web that uses Java script

    Marc L, are you 100% sure that the table does not exist and occur error 424 is due to undefined READYSTATE.READYSTATE_COMPLETE ?
    I got the following in another module.
    Please Login or Register  to view this content.


    Quote Originally Posted by Marc L View Post

    What's the value of READYSTATE.READYSTATE_COMPLETE in your code ?
    While not fixed, code will never work …
    It's why you get the error 424 : table does not exist 'cause the page is still loading !

  15. #15
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: download and set table in excel from web that uses Java script

    You want table 24. You get the error since the 12th table only has one row at index 0. Index 1 doesn't exist, so you can't access the cells method of an object that doesn't exist - hence the error

  16. #16
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: download and set table in excel from web that uses Java script

    This can be made more efficient, but it's a starter for 10, will need adapting as necessary:
    Please Login or Register  to view this content.

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: download and set table in excel from web that uses Java script

    Quote Originally Posted by lubbamkt View Post
    Marc L, are you 100% sure that the table does not exist and occur error 424 is due to undefined READYSTATE.READYSTATE_COMPLETE ?
    As I yet wrote if you get a table collection from the main table with an ID,
    inspecting this collection in Local variables window, you find wanted table is Item 10
    but don't forget a collection really starts from zero and not one …

    It's not first a VBA problem but just to know how to use a webbrowser (inspector tool),
    how works IE, understand an HTML webpage and …

    IE Busy and readyState properties works only for initial load of webpage.

    But when you click on a button that modifies the page, these properties stay at same status !
    As you can see on this forum and everywhere on the web, in this case you must check
    Document.readyState until "complete"

    If you put a Beep statement in your code just after the readyState loop after the click
    and you set IE.Visible = True, you must hear the Beep only when page finishes to update.

    Amend you code and post it in case of another issue …

    Edit : now with Kyle's code like the request method you already had in previous thread,
    you can leave IE and continue like this or using the clipboardData …

  18. #18
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: download and set table in excel from web that uses Java script

    Thx Kyle123, I found a bit difficult to use a static URL because the website provided is not the ultimate web page to download the web table. I need to enter a stock code and click search button. After I reach the next page, I found that the URL is the same as the previous web page. So I don't know how to use your code.

    [/LEFT]
    Quote Originally Posted by Kyle123 View Post
    This can be made more efficient, but it's a starter for 10, will need adapting as necessary:
    Please Login or Register  to view this content.

  19. #19
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: download and set table in excel from web that uses Java script

    Did you try my code?

  20. #20
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: download and set table in excel from web that uses Java script

    Amazing! It works perfectly, how should I amend the code if I want to change another stock code? How could I set the stock code as variable so that I can change it by,say, input box?

    Quote Originally Posted by Kyle123 View Post
    Did you try my code?

  21. #21
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: download and set table in excel from web that uses Java script

    Quote Originally Posted by Kyle123 View Post
    This can be made more efficient, but it's a starter for 10, will need adapting as necessary:
    Please Login or Register  to view this content.
    Hi Kyle123,

    I know this is a bit older question that you helped.

    Recently, I found the website has changed a bit (adding a hidden input data
    HTML Code: 
    whose value changes every time I send information to the server) so that I cannot use the solution you offered to me.

    Could you tell me the way to overcome this difficulty? Please

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Convert Excel Formula to Java Script
    By savio21 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2011, 01:06 PM
  2. Java Script to spreadsheet
    By Plan_B in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-17-2010, 10:44 PM
  3. java Script problem in excel on Mac machine
    By bhangale.parag in forum Excel General
    Replies: 0
    Last Post: 02-02-2009, 04:22 AM
  4. java script pop ups
    By Jim in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-21-2005, 06:05 PM
  5. How to remove a Java Script
    By Mac Lingo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-10-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1