Having trouble selecting a button using xpath in Scrapy Python?

I am currently attempting to scrape quotes from a website called using my spider code that looks something like this:

class quote(scrapy.Spider): name = 'quotes' # defining Name start_urls = [''] # Targeted urls

def parse(self, response):
    total_count = len(response.xpath('//dl/dt').getall())  # counter for loop        
    for i in range(1, total_count + 1):  # loop for retriving data continuosly

        xp_quote = f'//dl/dt[{i}]/a/text()'
        xp_writer = f'//dl/dd[{i}]/b/a/text()'
        page_quote_writer = response.xpath(xp_writer).get()
        page_quote = response.xpath(xp_quote).get()

        yield {  # dictionay return
            'Writer': (page_quote_writer if page_quote_writer != None else 'Unable to fetch'),
            'Quote': (page_quote if page_quote != None else 'Unable to fetch')
        }

    next_page = response.css('#content tbody td a::attr(href)').getall()
    print(next_page)

I have run into an issue with the "next_page" section where I cannot retrieve any data. I have double-checked with xpath as well, but the problem persists. I attempted to use Chrome's Inspect Element feature to copy the xpath and later the css selector, but it did not solve the issue. Interestingly, the same xpath and css selector work perfectly fine in Chrome's Inspect Elements Find section.

Any help would be greatly appreciated.

Answer №1

Give this xpath a shot:

//td[@id='content']//tbody//td//a[b]/@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

Dynamic Mat-select-trigger that automatically adjusts its size to fit the content

Currently, I am experimenting with an Angular Mat-Select that allows multiple selections. To display the selected values in the value field, I have implemented a custom Mat-Select-Trigger. My goal is to enable automatic resizing of the value field (similar ...

Is there a way to extract text that is not enclosed within an HTML tag?

<div class="subbold"> <span id="MainContentPlaceHolder_properties_lblBed_0">1</span>" Bed, 1 Bath "<span id="MainContentPlaceHolder_properties_PropertyType_1">1</span> </di ...

"An issue with IE9 causing small dots on rounded corners during rendering

Help Needed: Strange IE9 Rendering Issue I'm experiencing an odd rendering problem in Internet Explorer 9. You see those little white dots on the left? What could be causing them? Any suggestions on how to remove them? Microsoft, why always so myst ...

Rotating and moving two boxes using CSS3 transformations

I have two boxes, each measuring 200px by 200px, that I would like to animate using CSS animations. The first box (upper box) should rotate from rotateX(0deg) to rotateX(90deg) with a transform-origin of center top. The second box should follow the bottom ...

Is the second parameter of the function being used as a condition?

Why is it necessary to validate the helpText argument within the function to be non-equative to null when its ID is linked with the span tag? The functions task is to set and clear help messages in the form field using built-in CSS classes. <input id ...

What is the best way to insert a priority queue in this particular format?

Consider an array with 5 elements: [4, 8, 1, 7, 3]. These elements need to be inserted into a max-priority queue. Starting with an empty priority queue, the first element inserted is 4. Next, when 8 is inserted, it becomes the new front element since it is ...

What is the process for converting x and y coordinates to align with a fixed display?

When I make an API call, I am receiving X and Y coordinates in the following format: x: "-0.0120956897735595703" y: "0.147876381874084473" To display these coordinates on my minimap images, I have set their display to be absolute. The "left" and "top" pr ...

The margin and width of a div element with the position set to fixed and display set to table-cell are not rendering correctly

Is there a way to keep my .nav-container position: fixed; without creating a gap between it and the .page-content at certain window widths? When I set the position to fixed, a small white line appears between the red background of the .nav-container and th ...

Combining 1 pixel borders to create a bolder border effect

How can I prevent the border from becoming 2 pixels when I have overlapping (touching) divs? I thought about putting borders on only 2 sides, but then one edge of the div would be without a border. By the way, I am utilizing jQuery Masonry. ...

How can you ensure an element's height matches its width within an Ionic framework?

I am currently creating an application using the Ionic framework, and I am looking to set a square image as the background. The challenge is to ensure that the image scales appropriately for different screen resolutions; ideally, it should occupy the full ...

Utilize Pseudo Elements for Designing a Unique Background Overlay

I am aiming to create a div with a customizable background, and then utilize a pseudo element to generate a semi-transparent white overlay that will lighten the background of the div. The crucial requirement is for the "overlay" to appear beneath the conte ...

Permitting various valid responses for questions in a multiple-choice test | Utilizing Angular.js and JSON

As a beginner in this realm, I must apologize if my query seems naive. I recently crafted a multiple-choice quiz using HTML, CSS, JavaScript (angular.js), and a JSON data file following a tutorial I stumbled upon. The outcome pleased me, but now I am face ...

Application of id missing on all buttons in Bootstrap tour template

I'm having an issue with applying a new id to the next button in a Bootstrap tour template. I added the id to the button, but it only seems to work for the first stage and not the subsequent ones. Can anyone provide insight into why this might be happ ...

Implement a fullscreen popup dialog in a Python prompt_toolkit application

Currently, I am in the process of developing a terminal chat application that utilizes prompt_toolkit for its UI. Within the message box, I have integrated various commands to execute specific actions. To construct the Dashboard, I leveraged prompt_toolkit ...

Is there a way to restore a minimized min.css file?

Recently, I attempted to utilize an online tool for unminifying my CSS code. However, when I replaced the minified code with the unminified version and accessed the URL, I discovered that the entire website had lost its layout. Unfortunately, relying sole ...

Is it possible to eliminate the border on an image input button?

Here is the code I've been working on: HTML: <!DOCTYPE html> ... <form> <input type="image" value=" " class="btnimage" /> </form> ... CSS: .btnimage { width: 80px; height: 25px; background:url('C:/Users ...

Stripping CSS prefixes upon file initialization

When developing my application, I have a process in place where I load CSS files on the back-end using Express.JS and then transmit them to the front-end. However, before sending the CSS code to the front-end, I need to: Identify the user's browser; ...

The table is overflowing its parent element by exceeding 100% width. How can this issue be resolved using only CSS?

My root div has a width of 100% and I need to ensure that all children do not overlap (overflow:hidden) or exceed the 100% width. While this works well with inner <div>s, using <table>s often causes the table to extend beyond the parent 100% d ...

Adjust the image to stretch and crop appropriately to perfectly fit the specified dimensions

I have a div with an image inside of it, and the overflow of the div is set to hidden so that the image will be cropped if it exceeds the width or height. It was working correctly, but sometimes it doesn't. What could be causing this issue? Here is th ...

Steps to place a URL and Buttons over an existing header Image

1) I am working with a header JPEG image that is 996px wide and includes a square logo on the left side. My goal is to use only this square logo section and add an href tag so that when users hover over it, the cursor changes to a hand pointer and they are ...