title: Saving scrapped content into a dictionary in Python
body: <p>I try to count the number of words in different websites, however I get the <code>&quot;TypeError: 'str' object does not support item assignment&quot;</code>. Here is my code:</p>
  <pre><code>import requests
  from bs4 import BeautifulSoup as BS
  URL = &quot;https://www.coach.com/shop/women/handbags/view-all&quot;
  headers = {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)'}
  page = requests.get(URL, headers = headers)
  html_content= page.text
  soup = BS(html_content, &quot;lxml&quot;)
  content = {}
  try:
      text_counter = 0
      x = soup.find_all(&quot;h2&quot;)
      for y in x:
          title_length = len(y.get_text().split())
          text_counter += title_length
          content = y.findNext('p').get_text()
          content_length = len(y.findNext('p').get_text().split())
          text_counter += content_length
  
      t = soup.find_all(&quot;h3&quot;)
      for q in t:
          title_length = len(q.get_text().split())
          text_counter += title_length
          content = q.findNext('p').get_text()
          content_length = len(q.findNext('p').get_text().split())
          text_counter += content_length
      content[&quot;n_words&quot;] = text_counter 
  except:
      content[&quot;n_words&quot;] = &quot;&quot;
  </code></pre>
  <p>Full trace:</p>
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-2-34168cb72272&gt; in &lt;module&gt;
       26         text_counter += content_length
  ---&gt; 27     content[&quot;n_words&quot;] = text_counter
       28 except:
  
  TypeError: 'str' object does not support item assignment
  
  During handling of the above exception, another exception occurred:
  
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-2-34168cb72272&gt; in &lt;module&gt;
       27     content[&quot;n_words&quot;] = text_counter
       28 except:
  ---&gt; 29     content[&quot;n_words&quot;] = &quot;&quot;
  
  TypeError: 'str' object does not support item assignment
  </code></pre>