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

Responsive design in Android does not function as intended

My goal is to create a responsive design for my website, but I am encountering issues with importing the CSS files into the HTML. When I try to view the site in both the Windows version of Chrome and the Android version, all I see is a white screen. I am c ...

What is the best method for positioning span content above all other elements without having it wrap around them?

Each form element on my page is accompanied by a span that displays an error message, if applicable. The layout consists of two columns: left and right. I am struggling to make the span display seamlessly from the left column all the way across the page wi ...

The webpage failed to display the element despite its presence

from selenium import webdriver browser=webdriver.Firefox() browser.get("http://dollarupload.com/dl/08c646d60") browser.find_element_by_id("reg_download").click() elementlist=browser.find_elements_by_class_name("offer_title") I attempted to retrieve all el ...

Overlapping dynamic content causing CSS nested scrollbars to clash at full width of 100%

Displayed below is a layout with two nested divs, both featuring automatic vertical scrolling. Is there a CSS technique available to show the inner scrollbar while maintaining the inner div at 100% width? https://i.stack.imgur.com/HSKHH.png div { ba ...

What's the most effective method for implementing a stylesheet through Javascript in a style switcher?

I've been tackling the challenge of creating a style switcher for my website. Through utilizing .append() and if and else statements, I managed to make it work successfully. Take a look at the code below: HTML <select name="active_style" id="lol" ...

Guide on stacking a transformed 3D div on top of a masked layer with higher Z-index without success

I am attempting to stack a green div on top of a blue div using CSS transformations. The blue div acts as a masked layer, while the green div is a dialog that should appear on top. I have tried adjusting the z-index property, but the blue div always ends ...

Which specific transitionend (or animationend) event should I use for this application?

I'm feeling a bit lost when it comes to using transitionend (or if I should be using animationend in this scenario). I'm not sure whether to utilize var, node, or box. Essentially, I am a complete beginner in this case. My goal is to have my div ...

Specify the width of one element to always be the same as the width of another

One common challenge is maintaining the width of one element equal to another when the page loads (refer to link description here). However, it becomes tricky when the side width changes, such as resizing the browser window. Is there a way to dynamically ...

Unable to handle a POST request initiated by an HTML Form

Recently, I started working with Express and Bootstrap. While attempting to create a login form that triggers a POST request to the server, I encountered an issue where the page displays "The page isn't working" instead of loading a new HTML page. He ...

Error encountered in Python 2.7 with Selenium 2: 'NoneType' object does not possess the attribute 'group'

Having recently delved into the world of Python/Selenium, I've been encountering a persistent roadblock while attempting to adjust some code. Despite my efforts scouring the internet and experimenting with various tweaks for days on end, I find myself ...

Is there a way to seamlessly incorporate a PHP tag into a Bootstrap dropdown for perfect alignment?

In relation to this query: I have successfully integrated the if/else statement into the dropdown without any issues. However, upon using the dropdown on the website, I noticed that the item generated by the if/else statement – in this case, "log in" or ...

Overriding a CSS property with !important proves ineffective

I need to make adjustments to an old internal page that currently has the following CSS styling: table { font-family: "Arial"; font-size: 13px; text-align: left; border-collapse: collapse; border: 1px solid black; vertical-align: m ...

Is a fixed div located inside a fluid grid container?

Having developed a website with a fluid 12 column grid, I am looking to lock the position of a div in the right hand column once it reaches the top of the page (using something like StickyJs or a similar tool). However, when the fixed position is applied, ...

scraping disaster strikes - twisted critical error in scrapy

Recently, I decided to delve into the world of web scraping and started using scrapy 1.1.0rc3 with Python 3.5. As I followed a simple online tutorial, I encountered an error message that kept popping up: from twisted.internet import _win32stdio builtins.I ...

minimize javascript syntax (stackoverflow 2022)

I'm struggling with this puzzle game. Sometimes, when I start a new game, the pieces get shuffled incorrectly. I tried adding a function to fix it, but it doesn't seem to be working. It's really frustrating and I want to simplify the code as ...

svg viewbox cannot be adjusted in size

Struggling with resizing an SVG to 20px by 20px. The original code size of the SVG is quite large at 0 0 35.41 35.61: <!doctype html> <html> <head> <meta charset="utf-8"> <title>SVG</title> ...

Incorporate a link to an image following a click event toggle using Jquery

I managed to create a code snippet that toggles between two images when clicked, thanks to some assistance from stackoverflow. However, I am now looking to add a link to the second image that redirects users to another webpage, like The App Store. My ques ...

trouble with the layout of the table

Could you assist me in improving the design to enhance data clarity? Your help would be greatly appreciated. Thank you for your anticipated response. CSS File: table-layout: fixed; width: 100%; border-collapse: collapse; table-layout: fixed; ove ...

Obtain an additional Element within the JSON Path

I'm attempting to conform to library limitations and am in need of defining a JSON Path that retrieves the subsequent object within a list, based on the index of a particular value. Consider the following scenario: {[ x, details of x, ...

For a while now, I've been attempting to transform my paragraph into a block within a section that showcases elements in an inline-flex layout

I have been attempting to adjust the paragraph with the errorDate class so that it displays as a block element directly beneath the input element similar to the image provided here. The section is currently set to appear as an inline-flex. Below is the CS ...