How to get a specific HTML tags
<p>I'm trying to get a HTML tags if the item has no text.<br>
For instance: I am looping through all the "a" attributes(URL).<br>
However, some of the URL has text in it and some don't.<br>
In this case I'm trying to get the URL for the ones that don't have text on it.<br>
Therefore, I did something like this.</p>

<pre><code>response = requests.get('https://fw.tmall.com/tmall/ser/tmall_detail.htm?spm=a1z1g.2177293.0.0.qF9gPO&amp;service_code=ts-4078').text
soup = BeautifulSoup(response)
main_wrapper = soup.find('div',attrs={'id':'success-case'}).findAll('a')
for items in main_wrapper:
    dictionary = {}
    href = items['href']
    if items.string is None:
        print items['href']
    else:
        print items.string
</code></pre>

<p>How do I do it so that <code>if items.string is None:</code> get that item specific URL only and not all the URL?</p>

<blockquote>
  <p>I'm trying to get the URL for the ones that don't have text on it</p>
</blockquote>

<p>You could use list-comprehension</p>

<pre><code>hrefs = [a['href'] for a in main_wrapper if a.string is None]
</code></pre>

<blockquote>
  <p>get that item specific url only and not all the URL!</p>
</blockquote>

<p>Not clear what that means. Each <code>a</code> tag only has one, specific URL. You are iterating over a list of <code>a</code> tags, therefore you get a list of URLs</p>

<blockquote>
  <p>I want to get specific HTML attribute, in this case it would be IMG URL that's inside <code>&lt;a&gt;</code> </p>
</blockquote>

<p>Then you need another <code>find</code> method within the loop to extract out that <code>&lt;img&gt;</code> element to get the <code>src</code> attribute </p>

python parsing beautifulsoup