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 9258351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:22:43+00:00 2026-06-18T12:22:43+00:00

I have to collect some data from a website.My data is wrapped as div

  • 0

I have to collect some data from a website.My data is wrapped as div s.Inside each div there is a title tag.I need to get the text inside these title tags.How to do this.
I have written the following code.What modification I have to apply for acheiving the task

<?php
$str = '';
$page =  file_get_contents('http://www.sarkari-naukri.in/');
$dom = new DOMDocument();
$dom->loadHTML($page);
$divs = $dom->getElementsByTagName('div');
$i = 0;
$len = $divs->length;
while($i<$len) {
    $div = $divs->item($i++);
    $id = $div->getAttribute('id');
    if(strpos($id,'post-') !== false ) {
           // i need to get text inside title tag inside this div
        $title ='';//title should be stored here
        $str = $str.$title;
    }
}
echo $str;

SAMPLE HTML

<body>
    <div id = 'post-1'>
         <title>title 1</title>
    </div>
    <div id = 'post-2'>
         <title>title 2</title>
    </div>
    <div id = 'post-3'>
         <title>title 3</title>
    </div>
</body>
  • 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-18T12:22:44+00:00Added an answer on June 18, 2026 at 12:22 pm

    The following PHP DOMDOcument code:

    $id = $div->getAttribute('id');
    if (strpos($id,'post-') !== false) {
    

    can be expressed in Xpath 1.0 with a Xpath string functionDocs:

    //div[contains(@id, 'post-')]
    

    Reading: Any div element which has an id attribute containing the string post-. By the rules of Xpath you can further extend the expression like selectinig the title children of all those:

    //div[contains(@id, 'post-')]/title
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edited title I am using Core Data to store some data I collect from
I'm trying to collect some data from some webpage using python (they don't have
I have the following situation: I have an application that collects some data from
I'm building a system that need to collect some user sensitive data via secured
I have the next code to retrieve some data from a xml file. The
I have to collect accelerometer data from my Android phone, so I have made
I have some SerialPort code that constantly needs to read data from a serial
We have a huge performance problem in our app, we collect data from different
I'd like some advice on passing data from form to form. I need to
I need to upload some DATA inside and FTP server. Following stackoverflow posts on

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.