Advertisement
furas

BeautifulSoup - get items in row

Jul 22nd, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. import os
  2. import requests
  3. from bs4 import BeautifulSoup
  4.  
  5. URL = os.getenv('TEAM_URL', "http://www2.squawka.com/teams/arsenal/squad")
  6.  
  7. r = requests.get(URL)
  8.  
  9. soup = BeautifulSoup(r.text, "html.parser")
  10.  
  11. #------------
  12. print('\n--- version 1 ---\n')
  13.  
  14. table = soup.find("table", class_="browseteams")
  15. all_rows = table.find_all("tr")
  16.  
  17. for row in all_rows[1:]:
  18.     all_columns = row.find_all("td")
  19.     print(all_columns[1].text.strip())
  20.  
  21. #------------
  22. print('\n--- version 2 ---\n')
  23.  
  24. all_items = soup.find_all("td", class_="squad_playerphoto")
  25.  
  26. for item in all_items:
  27.     print(item.text.strip())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement