Python Forum
AttributeError: 'str' object has no attribute 'xpath'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'str' object has no attribute 'xpath'
Dear Members,

I am sorry for the repeated post. I posted on the wrong sub-forum and then realized that this sub-forum is the right one for me. I am sorry for the inconvenience.

I am very new to python. I am using the following code to extract the details of each product.

I am collecting product names from the original page and using each product link, I am collecting price, SKU, and frame information from the linked pages. However, I am getting an attribute error for the web-link command. One possible problem could be that the parsed link includes "".

I think the main problem is href="". The code would work if the link were href="/eyeglasses/fz1370"

Full python code:

import scrapy

class GlassSpider(scrapy.Spider):
    name = 'glass'
    allowed_domains = ['']
    start_urls = ['']

    def parse(self, response):
        names=response.xpath("//p[@class='pname col-sm-12']/a")
        for name in names:

            yield response.follow(url=link, callback=self.parse_glass, meta={'glass_name': name})

    def parse_glass(self, response):
        sku=response.xpath("//ul[@class='col-12 col-sm-6 default-content']/li[1]/text()").get()

            'glass_name': name,
            'price': price,
            'sku': sku,
            'frame': frame
I started working on python this week. I would highly appreciate if you can mention what specific change I should make to my codes to correct the attribute error

Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: 'NoneType' object in a parser - stops it apollo 4 1,119 May-28-2021, 02:13 PM
Last Post: Daring_T
  AttributeError: ResultSet object has no attribute 'get_text' KatMac 1 1,142 May-07-2021, 05:32 PM
Last Post: snippsat
  Python 3.9 : BeautifulSoup: 'NoneType' object has no attribute 'text' fudgemasterultra 1 3,280 Mar-03-2021, 09:40 AM
Last Post: Larz60+
  'NavigableString' object has no attribute 'h2' RandomCoder 5 2,072 May-20-2020, 09:01 AM
Last Post: Larz60+
  need help with xpath pythonprogrammer 1 1,474 Jan-18-2020, 11:28 PM
Last Post: snippsat
  AttributeError: 'str' object has no attribute 'xpath' nazmulfinance 4 5,172 Nov-11-2019, 05:15 PM
Last Post: nazmulfinance
  form.populate_obj problem "object has no attribute translate" pascale 0 1,997 Jun-12-2019, 07:30 PM
Last Post: pascale
  Error object has no attribute text hcyeap 3 10,619 May-21-2019, 07:12 AM
Last Post: buran
  AttributeError: 'Response' object has no attribute 'replace' Truman 12 14,978 Mar-20-2019, 12:59 AM
Last Post: ichabod801
  AttributeError: 'dict' object has no attribute 'is_active' (PyMongo And Flask) usman 0 3,046 Nov-20-2018, 09:50 PM
Last Post: usman

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020