SHARE
TWEET

BeautifulSoup - get items in row

furas Jul 22nd, 2018 (edited) 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top