How to pull div attributes with BeautifulSoup in Python
<p>I'm trying to pull this data (lat and lng):</p>

<pre><code>&lt;div class="location"
    lat="1234"
    lng="5678"
&gt;
</code></pre>

<p>This is giving me nothing:</p>

<pre><code>print (soup.find_all("div", { "class" : "location"}))
</code></pre>

<p>My eventual goal is to store these values in a dictionary. Thanks.</p>

<p>Your current <code>print</code> is returning a <em>list</em> of results:</p>

<pre><code>[&lt;div class="location" lat="1234" lng="5678"&gt;&lt;/div&gt;]
</code></pre>

<p>You can access these by iterating through each result:</p>

<pre><code>for r in results:
    print(r['lat'], r['lng'])
</code></pre>

<hr>

<p>A full example, with two <code>div</code> elements, looks like this:</p>

<pre><code>from bs4 import BeautifulSoup

html = """&lt;div class="location"
    lat="1234"
    lng="5678"
&gt;
&lt;div class="location"
    lat="9101"
    lng="1213"
&gt;"""
soup = BeautifulSoup(html, 'html.parser')
results = soup.find_all("div", { "class" : "location"})
for r in results:
    print(r['lat'], r['lng'])
</code></pre>

<p>This prints out two results:</p>

<pre><code>('1234', '5678')
('9101', '1213')
</code></pre>

python beautifulsoup