furas

BeautifulSoup - get items in row

Jul 22nd, 2018
108
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×