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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:17:08+00:00 2026-06-15T21:17:08+00:00

I am relatively new to using Scrapy or python for that matter. I am

  • 0

I am relatively new to using Scrapy or python for that matter. I am looking to extract the from a few different links and I am having issues using a HTMLXPathSelector expression (syntax). I have looked at extensive documentation for the proper syntax but have yet to figure out a solution.

Here is an example of a link I am trying to extract the ‘img src’ from:

Page I am trying to extract the img src url from

from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector

class GeekSpider(BaseSpider):
    name = "geekS"
    allowed_domains = ["geek.com"]
    start_urls = ["http://www.geek.com/articles/gadgets/kindle-fire-hd-8-9-on-sale-for-50-off-today-only-20121210/"]

    def parse(self, response):
        hxs = HtmlXPathSelector(response)
        imgurl = hxs.select("//div[@class='article']//a/img/@src").extract()
        return imgurl

I think I have figured out the syntax for the x.select statement but, since I am new to this syntax/method I am not sure.

Here is my items.py file, basically followed the scrapy tutorial for this:

from scrapy.item import Item, Field

class GeekItem(Item):
    imgsrc = Field()

To clarify: What I am looking to do is extract the img src url that is on the page. I dont need to extract all image src’s which I have already figured out(much easier).

I am just looking to narrow it down and only extract that particular url of the img src. (I will be using this across multiple pages on this site)

Any help is greatly appreciated!

EDIT – Updated Code I was getting some syntax errors with geek = geek() So I changed it slightly to hopefully be easier to understand and function

  • 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-15T21:17:10+00:00Added an answer on June 15, 2026 at 9:17 pm

    I believe your xpath expression should be more like this. I tested it on another page (the Amazon shipping center article) and it returned all ten of the clickable images.

    geek['imgsrc'] = x.select("//div[@class='article']//a/img/@src").extract()
    

    To fix your other issue, you need to import GeekItem into your GeekSpider code.

    from scrapy.spider import BaseSpider
    from scrapy.selector import HtmlXPathSelector
    from geekspider.items import GeekItem # I'm guessing the name of your project here
    
    class GeekSpider(BaseSpider):
        name = "geekS"
        allowed_domains = ["geek.com"]
        start_urls = ["http://www.geek.com/articles/gadgets/kindle-fire-hd-8-9-on-sale-for-50-off-today-only-20121210/"]
    
        def parse(self, response):
            item = GeekItem()
            hxs = HtmlXPathSelector(response)
            item['imgsrc'] = hxs.select("//div[@class='article']//a/img/@src").extract()
            return item
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

relatively new to python so excuse me if this has an obvious answer that
I'm relatively new to Vim and have been using it without issues so far.
I'm using jQuery tablesorter plugin. I'm relatively new to jQuery and need help from
Ok, I'm relatively new to using the mysqlpp library that is used in Visual
I'm relatively new to python and scrapy and am in need of some assistance
I'm relatively new to NHibernate, but have been using it for the last few
I am relatively new to using MSpec and as I write more and more
I am relatively new to multi-threading and want to execute a background task using
I'm relatively new to Struts2. I've started using ModelDriven to reduce overhead in development.
I have started using SqLite recently, so I am relatively new to it. I

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.