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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:58:35+00:00 2026-06-14T19:58:35+00:00

I have a html site with no ids or classes, just some links and

  • 0

I have a html site with no ids or classes, just some links and headings like this

<h1>Link category 1</h1>
<a href="somesite">Somename 1</a>
<a href="somesite">Somename 2</a>
<a href="somesite">Somename 3</a>
<a href="somesite">Somename 4</a>
<h1>Link category 2</h1>
<a href="somesite">Somename 5</a>
<a href="somesite">Somename 6</a>
<a href="somesite">Somename 7</a>
<a href="somesite">Somename 8</a>

And so on

Currently I am parsing all the links on the page with this code

$dom = new DOMDocument();
@$dom->loadHTML($content);
$xPath = new DOMXPath($dom);
$elements = $xPath->query("//a");

With that I can get the text from all of the links but what I want to do is divide it up so that I first get all the links after the first h1 and do something with that and then I get all the links after the second h1 and do something with that. There can be any number of links and any number of headings.

Anyone have any tips or possibly an example of how to go about doing this?

  • 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-14T19:58:36+00:00Added an answer on June 14, 2026 at 7:58 pm

    in my case I always know what the headings will be and it is a very small chance they will be the same as the headings text so I was able to use this

    $xPath->query("//a | //h1");
    

    to get all the and elements and then using an if statement to change the mysql insert query when a new heading was detected.

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

Sidebar

Related Questions

From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
Okay, so i have the following html added to a site using javascript/greasemonkey. (just
I have a web site that contains an HTML form, in this form I
I have a site where I would like an URL like: /Some maincategory name/{id}/Some
If I have html like the following on my own site how come it
I have an html file containing <img width=10 height=12 scr=https://www.site.com/yughggcfgh> <img width=11 height=15 scr=https://www.site.com/yughggcfghcvbcvb>
I'm designing an HTML 5 site using a header, article, and footer. I have
In my case, I have an HTML/CSS Menu in the site master . So,
I have sample site: /index.html /appcache.manifest /style.css /test.js index.html: <!DOCTYPE HTML> <html manifest=appcache.manifest> <head>
I have added multiple image upload to my site using HTML api's. I have

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.