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

The Archive Base Latest Questions

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

I crawl every page of a a website, but there is this problem now.

  • 0

I crawl every page of a a website, but there is this problem now.

If a page contains the class “td-cell align-right gray” and “td-cell align-right gray row-border” then write text() of both in item[‘price’].
But, if a page only contains “td-cell align-right gray row-border”, then write only text() in item[‘price’].

The Code:

from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from scrapy.http.request import Request
from Test01.items import Test01Item
from scrapy.utils.url import urljoin_rfc
from scrapy.utils.response import get_base_url
import urlparse



    class ScrapyOrgSpider(BaseSpider):
        name = "oeticket"
        allowed_domains = ["oeticket.com"]
        start_urls = ["http://www.oeticket.com/de/suche/?search_string=amaretto"]

        def parse(self, response):
            hxs = HtmlXPathSelector(response)
            items = []


            next_page = hxs.select("//li[@class='next-page navigation']/a/@href").extract()
            abs_page = []
            for g in next_page:
                abs_page.append("http://oeticket.com" + g )

            if not not abs_page:
                for e in abs_page:
                    yield Request(e, self.parse)

            next_event = hxs.select("//li[@class='event-item vevent']/a/@href").extract()
            abs_event = []
            for it in next_event:
                abs_event.append("http://oeticket.com" + it) 


            if not not abs_event:
                for s in abs_event:
                    yield Request(s, self.parse)

            deeper = hxs.select("//li[@class='performance-item vevent']/a/@href").extract()
            abs_deeper = []
            for c in deeper:
               abs_deeper.append("http://oeticket.com" + c)

            if not not abs_deeper:
                for d in abs_deeper: 
                    yield Request(d, self.parse)

            posts = hxs.select("//ul[@class='grid_10 horizontal-list clearfix']")
            preis = hxs.select("//tbody/tr")


            for post in posts:
                item = Test01Item()

                item["when"] = post.select("li[@class='when']/p/abbr/text()").extract() + post.select("li[@class='when']/h2/text()").extract()
                items.append(item)

            for post in posts:
                item = Test01Item()
                item["what"] = post.select("li[@class='what']/h2/text()").extract()
                items.append(item)

            for post in posts:
                item = Test01Item()
                item["where"] = post.select("li[@class='where']/h2/text()").extract()
                items.append(item)



            for prei in preis:
                item = Test01Item()
                item['url'] = response.url
                item['price'] = prei.select("td[@class='ticket_price td-cell ucase black strong align-right']/text()").extract()
                item['price'] = prei.select("td[@class='ticket_price td-cell ucase black strong align-right row-border']/text()").extract()
                item["func"] = prei.select("td[@class='td-cell align-right gray']/text()").extract()
                item["func"] = prei.select("td[@class='td-cell align-right gray row-border']/text()").extract()

                items.append(item)

            for item in items:
                yield item

Outcome:

{"when": ["Donnerstag,  7. Feb 2013 ", "20:00"]},
{"what": ["Amaretto"]},
{"where": ["kleines theater"]},
{"url": "http://www.oeticket.com/de/tickets/amaretto-salzburg-kleines-theater-482435/performance.html", "price": [], "func": []},
{"url": "http://www.oeticket.com/de/tickets/amaretto-salzburg-kleines-theater-482435/performance.html", "price": ["  15,90 EUR  "], "func": ["  Erm\u00e4\u00dfigung lt. Info - ACHTUNG: Ausweiskontrolle!  "]},

Expected Outcome:

{"when": ["Donnerstag,  7. Feb 2013 ", "20:00"]},
{"what": ["Amaretto"]},
{"where": ["kleines theater"]},
{"url": "http://www.oeticket.com/de/tickets/amaretto-salzburg-kleines-theater-482435/performance.html", "price": ["  22,50 EUR  "], "func": ["  Normalpreis  "},
{"url": "http://www.oeticket.com/de/tickets/amaretto-salzburg-kleines-theater-482435/performance.html", "price": ["  15,90 EUR  "], "func": ["  Erm\u00e4\u00dfigung lt. Info - ACHTUNG: Ausweiskontrolle!  "]},

How can I fix this Problem, with the blank Item-Fields?
Thank You!

  • 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-17T10:10:29+00:00Added an answer on June 17, 2026 at 10:10 am

    You have to check the list item, if the length of the list is 0

    item['price'] = prei.select("td[@class='ticket_price td-cell ucase black strong align-right']/text()").extract()
    if len(item['price']) == 0:
       item['price'] = prei.select("td[@class='ticket_price td-cell ucase black strong align-right row-border']/text()").extract()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is to crawl every page and every document starting from a certain
Im trying to crawl a secure page (https) such as google with curl but
How does one use curl to crawl a website but with a different session
Can I code my sitemap this way and expect Google to crawl every links
I'm new to everything. Please help. I'm trying to crawl every <div class=name><a href=/v/name/idlike123123ksajdfk>name</a></div>
I want to crawl a website and store the content on my computer for
There is a web-site to crawl, with POST-authentication. How can I, having login and
Is there a way to crawl all facebook fan pages and collect some information?
Or should I use a different hammer to fix this problem. I've got a
I've bumped into a problem while working at a project. I want to crawl

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.