Ways to extract href attributes from a div element using xpath

I currently have a div setup like this:

    <div class="widget-archive-monthly widget-archive widget"> 
    <h3 class="widget-header">Monthly <a href="http://myblog.com/blogs/my_name/archives.html">Archives</a></h3> 
    <div class="widget-content"> 
        <ul> 
            <li><a href="http://myblog.com/blogs/my_name/2010/10/">October 2010</a></li> 
            [...] (and so on) 
        </ul> 
    </div> 
</div> 

I am attempting to extract the URL values inside the widget-content division using xpath without including any other links like the one for "Archives," resulting in just these specific values:

        http://myblog.com/blogs/my_name/2010/10/
        http://myblog.com/blogs/my_name/2010/09/
        http://myblog.com/blogs/my_name/2010/08/
        ... and so forth ...

Answer №1

//div[@class="widget-content"]//a/@href

This XPath expression will extract the href values of links located within the widget-content division only.

Answer №2

the linked answer is related to XPath: finding the URL of a link by its text

"//a/@href"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to work around the CORS policy in order to fetch data from URLs?

I have been developing a tool that can analyze URLs from an uploaded CSV file, search the text content of each URL, and calculate the total word count as well as the occurrences of "saas" or "software". The goal is to generate a new CSV file with the origi ...

Get information from one div and implement it in a different div

I am working on an application that creates div boxes dynamically and loads images through AJAX to place inside these boxes. To avoid unnecessary loading, I want to check if a box already exists before loading images. If it does exist, then I would like t ...

Ways to dynamically assign a class to a single element within a group of identical elements

I have three identical items in the DOM. Specifically, I am referring to a moving line <span class="caret"></span> <ul> <li class="nav-item-1"> <a href="#">ITEM 1</a> <span class="caret"></span> ...

Content overflowing the container - Designed to adapt to different screen sizes

I'm currently working on a project within the Bootstrap 3 framework and struggling with an issue regarding text overflow in extra small view. The text is not behaving as expected, as it should stick to its container and break accordingly. I've ex ...

What is it about the phone screen that makes media content so captivating?

My phone has a resolution of 2280x1080. I noticed that when using the following code, the background color changes to blue on my phone: @media (max-width: 500px) { body { background-color: blue; } } Interestingly, this feature stops working once "compute ...

Align the central element in the Bootstrap menu between two other elements

My menu layout looks like this : .navbar { box-shadow: 0 5px 15px rgba(0, 0, 0, .15); background: #fff; border: 0; max-height: 73px } .navbar-center>span>a { display: inline-block; position: relative; } #header>.navbar>div:nth-child(2)> ...

Creating a new webpage that automatically populates with multiple images from a server using PHP

I'm inquiring about generating a webpage automatically from an HTML template, How can I create a new webpage from an HTML template and display multiple images from the server on the generated page? Please review my code below, Thank You. The follo ...

Within a container, there are two divs separated by a white bar

Hello everyone, I am in need of creating a unique slideshow for my website and I want to start by splitting a div into two sections using a slightly skewed diagonal line that is either semi-transparent black or solid white. I have searched extensively onli ...

Combining all elements of my application into a single HTML, JS, and CSS file

My AngularJS app has a specific structure that includes different directories for each component: theprojectroot |- src | |- app | | |- index.html | | |- index.js | | |- userhome | | | |- userhome.html | | | ...

What could be the reason for the extra tags being returned by YQL?

Currently, I am executing a query in the YQL console with the following data: select * from html where url='http://www.motorni-masla.net/index.php?main_page=product_oil_info&cPath=140&products_id=294&zenid=c8281021bbfed454176247900b3b9d4a ...

Symfony2 enhances Twig within the bundle - without impact

I am currently working on my first project using Symfony2 and encountering an issue with the template setup. The main Twig file I am using is called "index.html.twig" and is located in src/Gogs/CMSBundle/Resources/views/Default/index.html.twig. I am attem ...

Generate selection choices by looping through a JSON document

I am attempting to develop a search box that will provide autocomplete suggestions based on user input from a key-value pair in a json file. I initially thought using datalist would be the most suitable approach for this task, however, upon running the cod ...

I am struggling to style a form effectively with CSS grid

I am working on setting up a 2-column HTML form using CSS grid. In the first column, I have labels placed on individual rows. In the second column, I have form elements also placed on individual rows. This is my initial attempt at this task and I am sti ...

Validation for a datepicker embedded within a table

I'm facing a challenge and need some assistance. I want to validate if the "FROM (DATE)" is greater than the "TO (DATE)" without disabling the date selection, but instead prompting the user if the condition is not met. Any insights or solutions would ...

Encountering a situation where assertXpathCount() is returning 0 in Selenium RC

While attempting to retrieve the number of rows in a table using assertXpathCount(), I am consistently receiving an output of 0. I have been utilizing the Xpath provided by the browser for the <tr> element, yet the results remain unchanged. Are ther ...

Shifting hues of colors on website based on geographical location

Working on a new project, I encountered an issue with two elements sharing the same class but displaying different color shades. Has anyone experienced this before and knows what could be causing it? UPDATE Here is an excerpt of the code: The Class: .su ...

Cover the <img ...> tag in HTML using JavaScript

I'm currently working on creating a simple game involving sliding ice-blocks. I ran into an issue while testing this JSFiddle and I'm looking to "hide" the image/button triggered by the line alert('Game starts!');. I attempted using sta ...

What's causing my button to line up horizontally within a flexbox that is positioned vertically?

My button is aligned within the flex-box, shouldn't the elements be stacked in a column? I am working on a timer that features a row with two columns. One column contains an image while the other consists of a heading, a flexbox with four rectangles ...

How to trigger a horizontal scroll on load for a specific ID in HTMLDivElement

Looking for advice on how to make one of the horizontally scrolling DIV containers on a site scroll to a specific position onLoad. The challenge is that this particular container is located far down the page vertically, and we want it to scroll horizontall ...

Using JQuery to display and conceal div elements with a mouse click

My script is working perfectly for showing and hiding a specific div (#id) on click. The only thing I need to figure out is how to change the font color of the text "Click Here" based on whether the div with class "menu" is hidden or shown. When the "menu" ...