Python 3 Beautiful Soup find tag with colon
<p>I am trying to scrape this site and get two separate tags. This is what the html looks like.</p>

<pre><code>&lt;url&gt;
  &lt;loc&gt;
    http://link.com
  &lt;/loc&gt;
  &lt;lastmod&gt;date&lt;/lastmode&gt;
  &lt;changefreq&gt;daily&lt;/changefreq&gt;
  &lt;image:image&gt;
   &lt;image:loc&gt;
    https://imagelink.com
   &lt;image:loc&gt;
   &lt;image:title&gt;Item title&lt;/image:title&gt;
  &lt;image:image&gt;
&lt;/url&gt;
</code></pre>

<p>the tags I am trying to get are the loc and image:title. The problem I am having is the colon in the title tag. The code I have so far is</p>

<pre><code>r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')

for item in soup.find_all('url'):
    print(item.loc)
    #print image title
</code></pre>

<p>i have also tried to do just </p>

<pre><code>print(item.title)
</code></pre>

<p>but that doesn't work</p>

<p>You should parse it in <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-a-parser" rel="nofollow">"xml" mode</a> instead (requires <code>lxml</code> to be installed as well):</p>

<pre><code>from bs4 import BeautifulSoup

data = """
&lt;url&gt;
  &lt;loc&gt;
    http://link.com
  &lt;/loc&gt;
  &lt;lastmod&gt;date&lt;/lastmod&gt;
  &lt;changefreq&gt;daily&lt;/changefreq&gt;
  &lt;image:image&gt;
   &lt;image:loc&gt;
    https://imagelink.com
   &lt;/image:loc&gt;
   &lt;image:title&gt;Item title&lt;/image:title&gt;
  &lt;/image:image&gt;
&lt;/url&gt;"""

soup = BeautifulSoup(data, 'xml')

for item in soup.find_all('url'):
    print(item.title.get_text())
</code></pre>

<p>Prints <code>Item title</code>.</p>

<p>Note that I've applied several fixes to your XML string since it was initially non-well-formed.</p>

python python-3.x tags beautifulsoup bs4