none
Problem parsing data from accuweather in C# RRS feed

  • Question

  • I have used C# to grab data from sites in the past but I am having a problem parsing out the data from https://m.accuweather.com/en/us/detroit-mi/48226/extended-weather-forecast/348755

    So far I grab the data and it's put into a string, below is a sample of the data returned

                    

    <div class="govt-alert us ww-non-precipitation ww-deepskyblue ">
        <a href="https://m.accuweather.com/en/us/detroit-mi/48226/weather-warnings/348755">
            <i></i>
            <p>Freeze Warning in effect from Thursday, 12:00 AM EDT until Thursday, 8:00 AM EDT.  Source: U.S. National Weather Service</p>
        </a>
    </div>

            <div class="wx-cell" id="day1">
                <h3><a href="https://m.accuweather.com/en/us/detroit-mi/48226/daily-weather-forecast/348755">Wed Oct 17</a></h3>
                <table>
                    <tr>
                        <td class="icon">
                            <img align="center" src="https://vortex.accuweather.com/adc2010/m/images/icons/80x80/13.png" alt="MostlyCloudyShowers" /></td>
                        <td class="temp ltr">49&deg;<br />
                            <span>30&deg;</span></td>
                        <td class="temp rtl">49&deg;<br />
                            <span>30&deg;</span></td>
                    </tr>
                </table>
                <p>Clouds giving way to some sun</p>
                <p class="precip">
                    <img src="https://vortex.accuweather.com/adc2010/m/images/feature/umbrella-open.png" />50&#37;
                </p>
            </div>



            <div class="wx-cell" id="day2">
                <h3><a href="https://m.accuweather.com/en/us/detroit-mi/48226/daily-weather-forecast/348755?day=2">Thu Oct 18</a></h3>
                <table>
                    <tr>
                        <td class="icon">
                            <img align="center" src="https://vortex.accuweather.com/adc2010/m/images/icons/80x80/01.png" alt="Sunny" /></td>
                        <td class="temp ltr">51&deg;<br />
                            <span>40&deg;</span></td>
                        <td class="temp rtl">51&deg;<br />
                            <span>40&deg;</span></td>
                    </tr>
                </table>
                <p>Plenty of sunshine; cool</p>
                <p class="precip">
                    <img src="https://vortex.accuweather.com/adc2010/m/images/feature/umbrella-closed.png" />2&#37;
                </p>
            </div>

    I am looking to extract the date, high, and low temps. I looked up a couple examples but they all used the id tag and I couldn't figure out how to apply it.

    Wednesday, October 17, 2018 6:56 PM

All replies

  • Hello, 

    It looks like provided well-formed XML (XHTML).

    So, you should be able to load this fragment as XML-Document (fragment) and use XPATH to extract required data.


    Sincerely, Highly skilled coding monkey.

    Wednesday, October 17, 2018 7:39 PM
  • Also consider the specially designed AccuWeather API :

    ·         https://developer.accuweather.com/


    Thursday, October 18, 2018 5:52 AM
  • Hi Jsifuent,

    Thank you for posting here.

    For your question, you could use HtmlAgilityPack to search from node.

    You could install HtmlAgilityPack from NuGet Package Manager first.

    And then try the code in the link below.

    https://social.msdn.microsoft.com/Forums/en-US/88c65b68-dd8c-4af8-8d92-9dec9cff6578/can-anyone-help-me-how-to-fetch-this-web-site-data-?forum=csharpgeneral

    The string you provided is not the same with the string I see in the website. You could press F12 to see the string. I try to download from the website. But it seems like the website do not allow me to download string. 

    Here is the node you could use in the code from the link I provided before.

    doc.DocumentNode.SelectSingleNode("//li[@class='govt-alert us ww-non-precipitation ww-deepskyblue']")

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 18, 2018 7:20 AM
    Moderator
  • Thanks, I did email them and i'm waiting for a response. The problem with the API is that I couldn't find a way to get their 90 day forecast on the free version. I considered the paid version but since I would only need to make 1 api call a day I am trying alternatives before contacting their sales team. 
    Thursday, October 18, 2018 12:00 PM
  • Hi Jsifuent,

    Waiting for your update. If your question has been solved, please mark the useful reply answer.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 19, 2018 6:40 AM
    Moderator