Same as the comments, you are not getting any <td>
tags simply because they don't exist, especially for index [0]
. The first <tr>
tag in that table is this:
If you notice, it has headers inside. Basically, you should start your counter
at 1 instead of 0.
Another way to be sure that you're getting the correct rows is checking if they have classes. If you noticed, the proper <tr>
rows have classes inside them (odd
and even
). You can employ something like table.find_all("tr", class_=True)
to get them.
Sample code (note: coded in Python 2.7, but easy enough to modify to suit Python 3.x):
import requests as rq
from bs4 import BeautifulSoup as bsoup
url = "http://thinkgaming.com/app-sales-data/?page=1"
r = rq.get(url)
soup = bsoup(r.content)
table = soup.find("table", class_="table")
rows = table.find_all("tr", class_=True)
cols = [td.get_text().strip().encode("utf-8") for td in rows[0].find_all("td")]
print cols
Result:
['1', '10', '-', 'Clash of Clans', 'Free', 'n/a', '44,259']
[Finished in 2.8s]
Let us know if this helps.