Пытаюсь спарсить таблицу с этого сайта https://coinmarketcap.com/ (не реклама) Использую библиотеки requests, BeautifulSoup Таблица состоит из тегов thead и tbody Сама проблема заключается в том, на сколько я понимаю модуль requests не видит тег tbody То есть если спарсить тэг <table>, спарсить всю таблицу, вернётся тег thead. С чем это связанно понятия не имею. https://pastebin.com/SYrTFfVK --- Код
trs = soup.find('table') print(trs) Python trs = soup.find('table') print(trs) если выполнить этот код, выведет <table><thead><tr><th aria-label="#: activate to sort column ascending" class="cmc-table__cell cmc-table__header cmc-table__cell--sticky cmc-table__cell--sortable cmc-table__cell--left cmc-table__cell--sort-by__rank">#</th><th aria-label="Name: activate to sort column ascending" class="cmc-table__cell cmc-table__header cmc-table__cell--sticky cmc-table__cell--sortable cmc-table__cell--left cmc-table__cell--sort-by__name">Name</th><th aria-label="Market Cap: activate to sort column descending" class="cmc-table__cell cmc-table__header cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__market-cap">Market Cap</th><th aria-label="Price: activate to sort column descending" class="cmc-table__cell cmc-table__header cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__price">Price</th><th aria-label="Volume (24h): activate to sort column descending" class="cmc-table__cell cmc-table__header cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__volume-24-h">Volume (24h)</th><th aria-label="Circulating Supply: activate to sort column descending" class="cmc-table__cell cmc-table__header cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__circulating-supply">Circulating Supply</th><th aria-label="Change (24h): activate to sort column descending" class="cmc-table__cell cmc-table__header cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__percent-change-24-h">Change (24h)</th><th class="cmc-table__cell cmc-table__header cmc-table__cell--right">Price Graph (7d)</th><th class="cmc-table__cell cmc-table__header cmc-table__cell--right"></th></tr></thead></table> HTML <table><thead><tr><th aria-label="#: activate to sort column ascending" class="cmc-table__cell cmc-table__header cmc-table__cell--sticky cmc-table__cell--sortable cmc-table__cell--left cmc-table__cell--sort-by__rank">#</th><th aria-label="Name: activate to sort column ascending" class="cmc-table__cell cmc-table__header cmc-table__cell--sticky cmc-table__cell--sortable cmc-table__cell--left cmc-table__cell--sort-by__name">Name</th><th aria-label="Market Cap: activate to sort column descending" class="cmc-table__cell cmc-table__header cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__market-cap">Market Cap</th><th aria-label="Price: activate to sort column descending" class="cmc-table__cell cmc-table__header cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__price">Price</th><th aria-label="Volume (24h): activate to sort column descending" class="cmc-table__cell cmc-table__header cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__volume-24-h">Volume (24h)</th><th aria-label="Circulating Supply: activate to sort column descending" class="cmc-table__cell cmc-table__header cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__circulating-supply">Circulating Supply</th><th aria-label="Change (24h): activate to sort column descending" class="cmc-table__cell cmc-table__header cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__percent-change-24-h">Change (24h)</th><th class="cmc-table__cell cmc-table__header cmc-table__cell--right">Price Graph (7d)</th><th class="cmc-table__cell cmc-table__header cmc-table__cell--right"></th></tr></thead></table> Тут впринципе нет элемента tbody The post was merged to previous May 8, 2020 На страничке есть несколько таблиц, мб не ту берет The post was merged to previous May 8, 2020 а, лол, можешь сделать просто trs = soup.find('tbody') print(trs) Python trs = soup.find('tbody') print(trs) The post was merged to previous May 8, 2020 Выведет те самые данные, которые тебе нужны <tbody> <tr class="cmc-table-row" style="display:table-row"> <td class="cmc-table__cell cmc-table__cell--sticky cmc-table__cell--sortable cmc-table__cell--left cmc-table__cell--sort-by__rank"> <div class="">1</div> </td> <td class="cmc-table__cell cmc-table__cell--sticky cmc-table__cell--sortable cmc-table__cell--left cmc-table__cell--sort-by__name"> <div class="cmc-table__column-name sc-1kxikfi-0 eTVhdN"><img alt="Bitcoin" class="cmc-static-icon cmc-static-icon-1" height="16" src="https://s2.coinmarketcap.com/static/img/coins/32x32/1.png" width="16"/><a class="cmc-link" href="/currencies/bitcoin/" title="Bitcoin">Bitcoin</a></div> </td> <td class="cmc-table__cell cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__market-cap"> <div class="">$182,084,199,402</div> </td> <td class="cmc-table__cell cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__price"><a class="cmc-link" href="/currencies/bitcoin/markets/">$9,912.67</a></td> <td class="cmc-table__cell cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__volume-24-h"><a class="cmc-link" href="/currencies/bitcoin/markets/">$62,330,277,575</a></td> ... HTML <tbody> <tr class="cmc-table-row" style="display:table-row"> <td class="cmc-table__cell cmc-table__cell--sticky cmc-table__cell--sortable cmc-table__cell--left cmc-table__cell--sort-by__rank"> <div class="">1</div> </td> <td class="cmc-table__cell cmc-table__cell--sticky cmc-table__cell--sortable cmc-table__cell--left cmc-table__cell--sort-by__name"> <div class="cmc-table__column-name sc-1kxikfi-0 eTVhdN"><img alt="Bitcoin" class="cmc-static-icon cmc-static-icon-1" height="16" src="https://s2.coinmarketcap.com/static/img/coins/32x32/1.png" width="16"/><a class="cmc-link" href="/currencies/bitcoin/" title="Bitcoin">Bitcoin</a></div> </td> <td class="cmc-table__cell cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__market-cap"> <div class="">$182,084,199,402</div> </td> <td class="cmc-table__cell cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__price"><a class="cmc-link" href="/currencies/bitcoin/markets/">$9,912.67</a></td> <td class="cmc-table__cell cmc-table__cell--sortable cmc-table__cell--right cmc-table__cell--sort-by__volume-24-h"><a class="cmc-link" href="/currencies/bitcoin/markets/">$62,330,277,575</a></td> ...
MORTY, В том то и дело. Теперь посмотри на скрин https://prnt.sc/sd87p0 Те данные которые меня интересуют, находятся в теге tbody.