such a tree here New to parsing. Could not find the answer to your question in Google. Tried to get to the names of the series and pictures of them from the site lostfilm.tv - everything turned out. I decided to continue studying, I went to my favorite tracker rutor.org and it’s not working for me. I want to pull out the names of the torrents, but the names are stored in the links with the 'a' tag, all are in the tr tag with the class gai or tum, but! there are several tags referential 'a'. How to do it - I will not put my mind to it. My code does not give me anything. Tell me what I'm doing wrong. Lostfilm prokanalo everything, but here does not want

import requests from bs4 import BeautifulSoup url = 'http://rutor.info/search/0/1/0/0/2018' r = requests.get(url).text soup = BeautifulSoup(r, 'html.parser') trs = soup.findAll('tr', {'class':'gai'}) for link in trs: text = link.find('a') print (text.contents[0]) 

html piece:

  <a href="/torrent/667673/veb-kamera_cam-2018-webrip-kpk-l2" style="font-size: 12px !important; line-height: 14.6667px !important;">Веб-камера / Cam (2018) WEBRip | КПК | L2 </a> <table style="font-size: 16px !important; line-height: 19.3333px !important;" width="100%"><tbody style="font-size: 16px !important; line-height: 19.3333px !important;"><tr class="backgr" style="font-size: 16px !important; line-height: 19.3333px !important;"><td style="font-size: 12px !important; line-height: 14.6667px !important;" width="10px">Добавлен</td><td colspan="2" style="font-size: 12px !important; line-height: 14.6667px !important;">Название</td><td style="font-size: 12px !important; line-height: 14.6667px !important;" width="1px">Размер</td><td style="font-size: 12px !important; line-height: 14.6667px !important;" width="1px">Пиры</td></tr><tr class="gai" style="font-size: 16px !important; line-height: 19.3333px !important;"><td style="font-size: 12px !important; line-height: 14.6667px !important;">30&nbsp;Ноя&nbsp;18</td><td style="font-size: 12px !important; line-height: 14.6667px !important;"><a class="downgif" href="http://d.rutor.info/download/653854" style="font-size: 12px !important;"><img src="http://s.rutor.info/i/d.gif" alt="D"></a><a href="magnet:?xt=urn:btih:9e0b073af1107ba41936b3b487bd16bb31591d0b&amp;dn=rutor.info&amp;tr=udp://opentor.org:2710&amp;tr=udp://opentor.org:2710&amp;tr=http://retracker.local/announce" style="font-size: 12px !important;"><img src="http://s.rutor.info/i/m.png" alt="M"></a> <a href="/torrent/653854/kak-zhenit-holostjaka_destination-wedding-2018-bdrip-ot-megapeer-itunes" style="font-size: 12px !important; line-height: 14.6667px !important;">Как женить холостяка / Destination Wedding (2018) BDRip от MegaPeer | iTunes </a></td> <td style="font-size: 12px !important; line-height: 14.6667px !important;" align="right">39<img src="http://s.rutor.info/i/com.gif" alt="C"></td> <td style="font-size: 12px !important; line-height: 14.6667px !important;" align="right">1.43&nbsp;GB</td><td style="font-size: 12px !important; line-height: 14.6667px !important;" align="center"><span class="green" style="font-size: 12px !important; line-height: 14.6667px !important;"><img src="http://s.rutor.info/t/arrowup.gif" alt="S">&nbsp;27</span>&nbsp;<img src="http://s.rutor.info/t/arrowdown.gif" alt="L"><span class="red" style="font-size: 12px !important; line-height: 14.6667px !important;">&nbsp;32</span></td></tr><tr class="tum" style="font-size: 16px !important; line-height: 19.3333px !important;"><td style="font-size: 12px !important; line-height: 14.6667px !important;">30&nbsp;Ноя&nbsp;18</td><td style="font-size: 12px !important; line-height: 14.6667px !important;"><a class="downgif" href="http://d.rutor.info/download/667726" style="font-size: 12px !important;"><img src="http://s.rutor.info/i/d.gif" alt="D"></a><a href="magnet:?xt=urn:btih:9ad5d732c361692a1c0923f1abca206cd5c3a359&amp;dn=rutor.info&amp;tr=udp://opentor.org:2710&amp;tr=udp://opentor.org:2710&amp;tr=http://retracker.local/announce" style="font-size: 12px !important;"><img src="http://s.rutor.info/i/m.png" alt="M"></a> <a href="/torrent/667726/kak-zhenit-holostjaka_destination-wedding-2018-bdremux-1080p-ot-selezen-itunes" style="font-size: 12px !important; line-height: 14.6667px !important;">Как женить холостяка / Destination Wedding (2018) BDRemux 1080p от селезень | iTunes </a> 
  • Please add a piece of html to the question from which you want to pull out the names ( править button) - gil9red
  • damn, I can not understand how to add - Alexander Gninenko
  • Try this: print(text.text) Kst, can you add a piece of that table with links? - gil9red
  • You can try to search for the parts you need in terms using regular expressions, often it works faster and more reliably and depends little on changes in the structure of the page you are looking for. - Andrey Gornostaev
  • issued nothing. is empty. If trs, it will give an empty list. Meaning html code? - Alexander Gninenko

1 answer 1

Try:

 import requests from bs4 import BeautifulSoup url = 'http://rutor.info/search/0/1/0/0/2018' rs = requests.get(url) root = BeautifulSoup(rs.content, 'html.parser') for tr in root.select('tr.gai'): tds = tr.select('td') # У второго td нужные нам <a> td = tds[1] # Выводим текст ячейки print(td.text) 

If you need the link to pull out the text, then:

 ... for tr in root.select('tr.gai'): tds = tr.select('td') # У второго td берем третий <a> a = tds[1].select('a')[2] # Выводим текст ссылки print(a.text) 

UPD.

I took the code from the question:

 text = """ <table style="font-size: 16px !important; line-height: 19.3333px !important;" width="100%"> <tbody style="font-size: 16px !important; line-height: 19.3333px !important;"> <tr class="backgr" style="font-size: 16px !important; line-height: 19.3333px !important;"> <td style="font-size: 12px !important; line-height: 14.6667px !important;" width="10px">Добавлен</td><td colspan="2" style="font-size: 12px !important; line-height: 14.6667px !important;">Название</td><td style="font-size: 12px !important; line-height: 14.6667px !important;" width="1px">Размер</td><td style="font-size: 12px !important; line-height: 14.6667px !important;" width="1px">Пиры</td> </tr> <tr class="gai" style="font-size: 16px !important; line-height: 19.3333px !important;"><td style="font-size: 12px !important; line-height: 14.6667px !important;">30&nbsp;Ноя&nbsp;18</td><td style="font-size: 12px !important; line-height: 14.6667px !important;"><a class="downgif" href="http://d.rutor.info/download/653854" style="font-size: 12px !important;"><img src="http://s.rutor.info/i/d.gif" alt="D"></a><a href="magnet:?xt=urn:btih:9e0b073af1107ba41936b3b487bd16bb31591d0b&amp;dn=rutor.info&amp;tr=udp://opentor.org:2710&amp;tr=udp://opentor.org:2710&amp;tr=http://retracker.local/announce" style="font-size: 12px !important;"><img src="http://s.rutor.info/i/m.png" alt="M"></a> <a href="/torrent/653854/kak-zhenit-holostjaka_destination-wedding-2018-bdrip-ot-megapeer-itunes" style="font-size: 12px !important; line-height: 14.6667px !important;">Как женить холостяка / Destination Wedding (2018) BDRip от MegaPeer | iTunes </a></td> <td style="font-size: 12px !important; line-height: 14.6667px !important;" align="right">39<img src="http://s.rutor.info/i/com.gif" alt="C"></td> <td style="font-size: 12px !important; line-height: 14.6667px !important;" align="right">1.43&nbsp;GB</td><td style="font-size: 12px !important; line-height: 14.6667px !important;" align="center"><span class="green" style="font-size: 12px !important; line-height: 14.6667px !important;"><img src="http://s.rutor.info/t/arrowup.gif" alt="S">&nbsp;27</span>&nbsp;<img src="http://s.rutor.info/t/arrowdown.gif" alt="L"><span class="red" style="font-size: 12px !important; line-height: 14.6667px !important;">&nbsp;32</span></td> </tr> <tr class="tum" style="font-size: 16px !important; line-height: 19.3333px !important;"><td style="font-size: 12px !important; line-height: 14.6667px !important;">30&nbsp;Ноя&nbsp;18</td><td style="font-size: 12px !important; line-height: 14.6667px !important;"><a class="downgif" href="http://d.rutor.info/download/667726" style="font-size: 12px !important;"><img src="http://s.rutor.info/i/d.gif" alt="D"></a><a href="magnet:?xt=urn:btih:9ad5d732c361692a1c0923f1abca206cd5c3a359&amp;dn=rutor.info&amp;tr=udp://opentor.org:2710&amp;tr=udp://opentor.org:2710&amp;tr=http://retracker.local/announce" style="font-size: 12px !important;"><img src="http://s.rutor.info/i/m.png" alt="M"></a> <a href="/torrent/667726/kak-zhenit-holostjaka_destination-wedding-2018-bdremux-1080p-ot-selezen-itunes" style="font-size: 12px !important; line-height: 14.6667px !important;">Как женить холостяка / Destination Wedding (2018) BDRemux 1080p от селезень | iTunes </a> """ from bs4 import BeautifulSoup root = BeautifulSoup(text, 'html.parser') for tr in root.select("tr.gai") + root.select("tr.tum"): tds = tr.select('td') # У второго td нужные нам <a> td = tds[1] # Выводим текст ячейки print(td.text.strip()) # ВТОРОЙ СПОСОБ # У второго td берем третий <a> a = tds[1].select('a')[2] # Выводим текст ссылки print(a.text.strip()) print() 

Console:

 Как женить холостяка / Destination Wedding (2018) BDRip от MegaPeer | iTunes Как женить холостяка / Destination Wedding (2018) BDRip от MegaPeer | iTunes Как женить холостяка / Destination Wedding (2018) BDRemux 1080p от селезень | iTunes Как женить холостяка / Destination Wedding (2018) BDRemux 1080p от селезень | iTunes 
  • gave nothing: ( returns the void - Alexander Gninenko
  • and I won’t think how I can copy the code I need from the Mozilla inspector, it does not stand out in pieces - Alexander Gninenko
  • @AlexanderGninenko, so it works exactly: through the right mouse button, open the page source code and select from there. Could it be that the table with torrents is loaded after the page loads? Like through ajax? - gil9red
  • added to the main post, it turned out kabzdets some. As for what you asked, I honestly don’t know. - Alexander Gninenko
  • @AlexanderGninenko listen, but do you even have something with the rutor in the script given? Maybe your site is blocked by the provider? The script goes directly, and not through a proxy, like a browser - strawdog