+ Reply to Thread
Results 1 to 14 of 14

Web Scraping

  1. #1
    Registered User
    Join Date
    05-27-2020
    Location
    Gainesville, FL
    MS-Off Ver
    365
    Posts
    7

    Web Scraping

    Hello,

    I need help trying to get the 1st line of the following 10-day forecast. Here is my code to get the forecast for Miami, FL on Weather.com. I am not able to get the current date or the first date in the summary. Please help. Thanks and take care.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by alansidman; 09-28-2020 at 08:35 AM.

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Web Scraping

    So what exactly is happening? Are you able to capture any element value on that web page? Because you are using the get element by ID method from the document object model as a sub method of get elements by class name. I've never seen that done in my 20 years of doing this type of work.

    What do you mean that you need help getting the first line from the web page? And are you sure the element that you are targeting or that you are trying to capture actually has an ID attribute and that it's actually classified as the type of class you are pointing to?

  3. #3
    Registered User
    Join Date
    05-27-2020
    Location
    Gainesville, FL
    MS-Off Ver
    365
    Posts
    7

    Re: Web Scraping

    The code I included in my post captures a 10 day forecast for Miami, FL, even though the forecast has 14 days on the site. The code no longer gets the first day (today's forecast) but captures all other 13 days in the forecast. Maybe the ID attribute changed for today's forecast?!

  4. #4
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Web Scraping

    Well based on the code that you wrote and the fact that you're looking at every element in a loop, I would seriously doubt that the first element that's supposed to give you what you're looking for should not work. However, have you looked at the web pages source code to make sure that the code you're looking at is actually accurate?if the ID attribute of the element that you were missing did indeed change, you would certainly see it by looking at the source code of the web page.

    The other thing you should know is that a lot of sophisticated websites or websites that are run by technology companies that have been around forever, a lot of that crap is spit out by servers on an automated basis and people aren't even writing code anymore. So given that reality, who knows what goes on inside those companies.

    Furthermore, a little off topic here but,there's also a boatload of things that you can do on a web page in terms of using HTML elements to display content in a legitimate manner and an illegitimate manner. you can actually write an entire web pages source code and hide it behind the page that's actually visible. But doing so will get you blacklisted by search engines.

  5. #5
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,149

    Re: Web Scraping

    This alternative fetches day & night temperatures and the summary;

    Please Login or Register  to view this content.

  6. #6
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Web Scraping

    Haluk,

    I might be wrong about this but the URL that you included in that code of yours looks like you ran a search and the web app produced a hash output assigned to that search temporarily. and if that's the case that solution is not going to work for the question ask her here because that hash is going to be outdated very soon. And therefore it'll result in a page server error.

    As far as I know almost every web application in the world, when you run a search by clicking a search button produces some sort of identification hash like the one you just posted. And it's never good forever it expires at some point.

  7. #7
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,149

    Re: Web Scraping

    I just used the URL which was given in the original post, but you may probably correct.

    If that's the case, the related hash should be fetched and then the request should be sent.

  8. #8
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Web Scraping

    There's no way to fetch a hash because it's generated dynamically by the server when the search button is pressed

  9. #9
    Registered User
    Join Date
    05-27-2020
    Location
    Gainesville, FL
    MS-Off Ver
    365
    Posts
    7

    Re: Web Scraping

    Haluk, thanks for the help. I can definitely work with this. Take care!

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,871

    Re: Web Scraping

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  11. #11
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Web Scraping

    ..hash output assigned to that search temporarily.
    Nah, this one is place ID held on backend side from the looks of it. Not dynamically generated hash. You can trace it using Developer tool in the browser.
    0.JPG

    You can also test it by changing "tenday" portion of URL with "today". Same ID is used for Miami, FL.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  12. #12
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Web Scraping

    Quote Originally Posted by CK76 View Post
    Nah, this one is place ID held on backend side from the looks of it. Not dynamically generated hash. You can trace it using Developer tool in the browser.
    Attachment 697293
    wow that's actually pretty useful. thanks much. a lot of what I've seen is generally dynamically and assigned timeouts. but apparently not in this case. nice.

  13. #13
    Registered User
    Join Date
    05-27-2020
    Location
    Gainesville, FL
    MS-Off Ver
    365
    Posts
    7

    Re: Web Scraping

    Sorry, but is there a way of getting a code that fetches the data faster? I made the code work, but it takes a long time to run the code for multiple cities in my sheet.

  14. #14
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Web Scraping

    Gomez,

    If you have to run separate URLs and separate hashes for each City then obviously the code cannot run faster because every hash and every URL has to go through its own rendering process so essentially you're doing it as fast as you possibly can. That's my view on it anyway. The only chance you've got to make it faster is to use a more sophisticated language that has been a resources and VBA and that's pretty much any language in the world. Just pick one. Python, c sharp, c++,, anything.

+ 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. web scraping
    By midoan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-24-2018, 08:00 AM
  2. Web Scraping
    By CheekyMonkeh in forum Excel General
    Replies: 1
    Last Post: 10-15-2018, 02:43 PM
  3. help from web scraping
    By kirby21 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-31-2015, 08:59 PM
  4. help web scraping vba
    By kirby21 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-24-2015, 09:34 PM
  5. Web scraping
    By vijay.jp in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-02-2015, 12:56 AM
  6. New to VBA - Web Scraping
    By cringle in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 12-17-2013, 08:26 AM
  7. [SOLVED] Web scraping with xml
    By abousetta in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-24-2012, 05:25 AM

Tags for this Thread

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