title: Any way to impove code with several if nested?
body: <p>I wrote this code with nested <code>if else</code> cases, but I feel it's so ugly and wonder if there's any way to improve it (or any better way to accomplish this).</p>
  
  <pre><code>def do_something(self, response):
      a_url = response.css('a.classA::attr(href)').extract_first()
      if a_url:
          a_url = a_url.split('&amp;')[0]
      else:
          a_url = response.css('a.classB::attr(href)').extract_first()
          if a_url:
              a_url = a_url.split('&amp;')[0]
          else:
              logger.error('get no url')
      if a_url:
          yield Request(
              url=a_url,
              dont_filter=True,
              callback=self.do_next_thing
          )
  </code></pre>
  
  <p>The main concern is that I wanna extract a url/link from a response, and then <strong>split</strong> it and get the first element. But <strong>a_url</strong> only exists in one of two(or may be more) elements. I can't do the <strong>split</strong> directly because <strong>a_url</strong> may be <code>NoneType</code>. I wanna try with <code>try except else</code> but that seems getting even more complicated.</p>
  
  <p>Any better solutions?</p>