title: Web-scrapeing a table to a list
body: <p>I'm trying to extract a table from a webpage. I have managed to get all the data in the table into a list. However all the table data is being put into one list element. I need assistance getting the 'clean' data (i.e. the strings, without all the HTML packaging) from the rows of the table into their own list elements.</p>
  <p>So instead of...</p>
  <pre><code>list  = [&lt;tr&gt;
           &lt;th&gt;&lt;a href=&quot;/7.62x25mm_TT_AKBS&quot; title=&quot;7.62x25mm TT AKBS&quot;&gt;&lt;img alt=&quot;TTAKBS.png&quot; decoding=&quot;async&quot; height=&quot;64&quot; src=&quot;https://static.wikia.nocookie.net/escapefromtarkov_gamepedia/images/6/61/TTAKBS.png/revision/latest/scale-to-width-down/64?cb=20190519001904&quot; width=&quot;64&quot;/&gt;&lt;/a&gt;
           &lt;/th&gt;
           &lt;th&gt;&lt;a href=&quot;/7.62x25mm_TT_AKBS&quot; title=&quot;7.62x25mm TT AKBS&quot;&gt;7.62x25mm TT AKBS&lt;/a&gt;
           &lt;/th&gt;
           &lt;td&gt;58
           &lt;/td&gt;
           &lt;td&gt;12
           &lt;/td&gt;
           &lt;td&gt;32]
  </code></pre>
  <p>I would like...</p>
  <pre><code>list  = ['href=&quot;/7.62x25mm_TT_AKBS&quot; title=&quot;7.62x25mm TT AKBS&quot;&gt;&lt;img alt=&quot;TTAKBS.png&quot; decoding=&quot;async&quot; height=&quot;64&quot; src=&quot;https://static.wikia.nocookie.net/escapefromtarkov_gamepedia/images/6/61/TTAKBS.png/revision/latest/scale-to-width-down/64?cb=20190519001904&quot; width=&quot;64&quot;',
           'href=&quot;/7.62x25mm_TT_AKBS&quot; title=&quot;7.62x25mm TT AKBS&quot;&gt;7.62x25mm TT AKBS',
           '58',
           '12',
           '32']
  </code></pre>
  <p>My code and <code>list</code> can be replicated using the following.</p>
  <pre><code>#Import Modules
  import re
  import requests
  from bs4 import BeautifulSoup
  
  #Get page
  cartridge_url = 'https://escapefromtarkov.gamepedia.com/7.62x25mm_Tokarev'
  cartridge_page = requests.get(cartridge_url)
  cartridge_soup = BeautifulSoup(cartridge_page.content, 'html.parser')
  
  #This gets the rows of the table I want
  list = cartridge_soup.find_all(lambda t: t.name =='tr')
  
  #This gets rid of an element which is not useful
  list = [n for n in dirty_temp_type if not 'class=&quot;va-navbox' in str(n)]
  
  #I had hoped this might assemble a list..  
  list = [str(n) for n in list]
  </code></pre>
  <hr />
  <p>I'm learning python, I think I grasp HTML, but I cannot get python to interact with my <code>bs4.element.ResultSet</code>. I know this is not a sophisticated solution but I have hit a brick wall after trying a number of different approaches. My 'true' end goal is a list like the following...</p>
  <pre><code>list  = ['7.62x25mm_TT_AKBS',
           '58',
           '12',
           '32']
  </code></pre>
  <hr />
  <p><strong>Attempts to Implement Suggested Solutions:</strong></p>
  <p>---&gt; As suggested by <a href="https://stackoverflow.com/users/6505847/azycrw4282">AzyCrw4282</a></p>
  <p><em>That's an incredible username btw.</em></p>
  <p><strong>(i)</strong></p>
  <p>I [think I] can see roughly what I'm supposed to do but I'm failing to properly implement it.</p>
  <p>Using...</p>
  <pre><code>cartridge_table = cartridge_soup.find_all('table')
  </code></pre>
  <p>I get what looks to be all the right data in HTML format stored inside <code>cartridge_table</code>. However, running...</p>
  <pre><code>for row in cartridge_table.find_all(&quot;tr&quot;)[:1]:
      print([cell.get_text(strip=True) for cell in row.find_all(&quot;td&quot;)])
  </code></pre>
  <p>...returns...</p>
  <pre><code>ResultSet object has no attribute 'find_all'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
  </code></pre>
  <p>... and replacing <code>find_all</code> with <code>find</code> doesn't remedy the issue.</p>
  <p><strong>(ii)</strong></p>
  <p>I half-heartedly ran...</p>
  <pre><code>for row in cartridge_soup.find_all(&quot;tr&quot;)[:1]:
      print([cell.get_text(strip=True) for cell in row.find_all(&quot;td&quot;)])
  </code></pre>
  <p>...but this returns an empty list.</p>
  <p><strong>(iii)</strong></p>
  <p>The question you originally linked to defines a variable called <code>header</code> prior to filling the <code>table</code> variable with the necassary data...</p>
  <pre><code>header = soup.find(&quot;b&quot;, text=&quot;Payable&quot;)
  table = header.find_parent(&quot;table&quot;)
  </code></pre>
  <p>I'm not grasping what to replace &quot;Payable&quot; with to get this to work for me.</p>
  <p><strong>(iv)</strong></p>
  <p>I tried to negate the above problem in <em>(iii)</em> by giving this a stab...</p>
  <pre><code>cartridge_table = cartridge_soup.find_parent(&quot;table&quot;)
  
  for row in cartridge_soup.find_all(&quot;tr&quot;)[:1]:
      print([cell.get_text(strip=True) for cell in row.find_all(&quot;td&quot;)])
  </code></pre>
  <p>But it returns an empty list. When I checked it's because nothing gets stored under the <code>cartridge_table</code> variable.</p>
  <p><strong>(V)</strong></p>
  <p>I tried running...</p>
  <pre><code>header = cartridge_soup.find(&quot;b&quot;, text=&quot;Payable&quot;)
  </code></pre>
  <p>... and replacing <code>&quot;Payable&quot;</code> with a variety of seemingly sensible alternatives to see what would happen, but I got nowhere. Ultimately the <code>header</code> variable always seemed to remain empty.</p>
  <p>Examples: <code>&quot;Icon&quot;</code>, <code>&quot;Name&quot;</code>, <code>&quot;Fragmentation Chance&quot;</code>, <code>&quot;wikitable sortable&quot;</code>, <code>&quot;7.62x25mm TT LRN&quot;</code>, <code>&quot;7.62x25mm_TT_AKBS&quot;</code>.</p>