Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8691223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:04:45+00:00 2026-06-13T00:04:45+00:00

I want to scrape a star based rating, that is the corresponding code <div

  • 0

I want to scrape a star based rating, that is the corresponding code

<div class="product_detail_info_rating_stars">
    <div class="product_detail_star full"></div>
    <div class="product_detail_star full"></div>
    <div class="product_detail_star full"></div>
    <div class="product_detail_star full"></div>
    <div class="product_detail_star"></div>
</div>

Every rating has this codesnippet. I am looking for a way to convert these snippets into numbers like this one would be a 4 (4 of 5 stars).

The way that comes to my mind is to match the whole block for each rating and then match the full class and count it, but maybe there is a better way that I am not seeing.

Is there a better way to solve this problem?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:04:46+00:00Added an answer on June 13, 2026 at 12:04 am

    Here is a quick example of how you can use SimpleXML parser and XPath.

    // Get your page HTML string
    $html = file_get_contents('1page.htm');
    
    // To suppress invalid markup warnings
    libxml_use_internal_errors(true);
    
    // Create SimpleXML object
    $doc = new DOMDocument();
    $doc->strictErrorChecking = false;
    $doc->loadHTML($html);
    $xml = simplexml_import_dom($doc);
    
    // Find a nodes
    $blocks = $xml->xpath('//div[contains(@class, "product_detail_info_rating_stars")]');
    
    foreach ($blocks as $block)
    {
        $count = 0;
        foreach ($block->children() as $child) {
            if ($child['class'] == 'product_detail_star full') {
                $count++;
            }
        }
        echo '<pre>'; print_r('Rating: ' . $count . ' of ' . $block->count()); echo '</pre>';
    }
    
    // Clear invalid markup error buffer
    libxml_clear_errors();
    

    For test html page like this:

    <!doctype html>
    <html>
    <head></head>
    <body>
    
    <table>
        <tr>
            <td>
                <div class="product_detail_info_rating_stars">
                    <div class="product_detail_star full"></div>
                    <div class="product_detail_star"></div>
                    <div class="product_detail_star"></div>
                    <div class="product_detail_star"></div>
                    <div class="product_detail_star"></div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="product_detail_info_rating_stars">
                    <div class="product_detail_star full"></div>
                    <div class="product_detail_star full"></div>
                    <div class="product_detail_star"></div>
                    <div class="product_detail_star"></div>
                    <div class="product_detail_star"></div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="product_detail_info_rating_stars">
                    <div class="product_detail_star full"></div>
                    <div class="product_detail_star full"></div>
                    <div class="product_detail_star full"></div>
                    <div class="product_detail_star full"></div>
                    <div class="product_detail_star"></div>
                </div>
            </td>
        </tr>
    </table>
    
    </body>
    </html>
    

    It will output something like:

    Rating: 1 of 5
    Rating: 2 of 5
    Rating: 4 of 5
    

    Play with this to adjust to your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that I want to scrape that has the following format:
I have a webpage that I want to scrape using regex. The page may
I want to scrape string data from some binary text files that contain embedded
I want to screen-scrape a web-site that uses JavaScript. There is mechanize , the
I want to scrape data from PHP web pages that are behind a login
I want to scrape some information from a pokerplatforms webpage. For that I need
I want to scrape some html pages that have nested form elements with lxml.
I want to scrape a page that regularly updates (adding new articles with exactly
There's a website that I want to scrape (FWIW it's svpply ) and there's
I have an external HTML source that I want to scrape and either transform

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.