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

  • Home
  • SEARCH
  • 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 8426457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:32:17+00:00 2026-06-10T04:32:17+00:00

I have a project where I have to scrape many URLs from many pages.

  • 0

I have a project where I have to scrape many URLs from many pages. I thought the structure of every page would remain the same, but sometimes it changes and breaks my code.

I need to extract, for example, the abstract of an article and its keywords, both of which are in a separate <p> with the same class "marginB3". So I scraped a page and only got two results, one for the abstract and the other one for the keywords:

hxs = HtmlXPathSelector(response)
lista =  hxs.select('//p[@class="marginB3"]/text()')  
self.abstracto = lista[0].extract()
self.keywords = lista[1].extract()

I then tried with a third page and a new <p> appeared with some additional information about the article and altered the structure. That made it more complicated since there are no ids and only classes. How can I differentiate which one is the <p> for the keywords without id’s if they have their own <h2> above them:

<h2>Info</h2>
<p class="marginB3">a_url_I_want</p>

Can I do this differentiation by reading that <h2> and then the <p> below it?

  • 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-10T04:32:18+00:00Added an answer on June 10, 2026 at 4:32 am

    You certainly can.

    Try this:

    # First <p>
    hxs.select('//h2/following-sibling::p[@class="marginB3"][1]/text()').extract()
    # Second <p>
    hxs.select('//h2/following-sibling::p[@class="marginB3"][2]/text()').extract()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following folder structure /project /scrape item.py /spiders myscraper.py inside the file
I have project Emle in Launchpad . I set it to import from emle.svn.sourceforge.net
Every project on drupal.org has its own page: http://drupal.org/project/marinelli When a new release is
i have project in .net , i want to test it. But i dont
We have project with a server witch have about 3000 requests at day from
I have project containing few user controls (each represents a game, but that's irrelevant),
I have project that creates dlls. These dlls are invoked from python later by
I'm working on a project to scrape statistics from Fantasy Football leagues across various
I have a Scrapy project that I want to use to scrape some websites.
We have project (PHP application), but instalation for each client vary, sometimes very little,

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.