Python Forum
Need help with Beautiful Soup - table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with Beautiful Soup - table
#2
this works here

from urllib.request import urlopen
from bs4 import BeautifulSoup as bsoup

url = 'http://www.cfbstats.com/2018/team/234/index.html'

ofile = urlopen(url)
soup = bsoup(ofile, "html.parser", from_encoding='utf-8')
soup.prettify()

table = soup.find("table", attrs={"class":"team-schedule"})

datasets = []
mytable = table.find_all("tr")#[1:]
for row in mytable:
    text = str(row.get_text()).split('\n')
    datasets.append(text)

_len = len(datasets)
for x in range(_len -1):
    t = datasets[x]
    print((t[1] + '\t' + t[2] + '\t' + t[5]).expandtabs(30))
Output:
Date Opponent Attendance 09/03/18 Virginia Tech 75,237 09/08/18 Samford 72,239 09/15/18 @ 17 Syracuse 37,457 09/22/18 Northern Ill. 65,633 09/29/18 @ Louisville 52,798 10/06/18 @ Miami (Fla.) 65,490 10/20/18 Wake Forest 67,274 10/27/18 2 Clemson 68,403 11/03/18 @ North Carolina St. 57,600 11/10/18 @ 3 Notre Dame 77,622 11/17/18 Boston College 57,274 11/24/18 10 Florida 71,953
Reply


Messages In This Thread
Need help with Beautiful Soup - table - by jlkmb - Dec-15-2018, 08:10 PM
RE: Need help with Beautiful Soup - table - by Axel_Erfurt - Dec-15-2018, 10:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Beautiful Soup - access a rating value in a class KatMac 1 3,482 Apr-16-2021, 01:27 PM
Last Post: snippsat
  *Beginner* web scraping/Beautiful Soup help 7ken8 2 2,630 Jan-28-2021, 04:26 PM
Last Post: 7ken8
  Help: Beautiful Soup - Parsing HTML table ironfelix717 2 2,704 Oct-01-2020, 02:19 PM
Last Post: snippsat
  Beautiful Soup (suddenly) doesn't get full webpage html j.crater 8 17,027 Jul-11-2020, 04:31 PM
Last Post: j.crater
  Requests-HTML vs Beautiful Soup - How to Choose? robin73 0 3,834 Jun-23-2020, 02:53 PM
Last Post: robin73
  looking for direction - scrappy, crawler, beautiful soup Sly_Corn 2 2,472 Mar-17-2020, 03:17 PM
Last Post: Sly_Corn
  Beautiful soup truncates results jonesjoz 4 3,902 Mar-09-2020, 06:04 PM
Last Post: jonesjoz
  Beautiful soup and tags starter_student 11 6,205 Jul-08-2019, 03:41 PM
Last Post: starter_student
  Beautiful Soup find_all() kirito85 2 3,389 Jun-14-2019, 02:17 AM
Last Post: kirito85
  [split] Using beautiful soup to get html attribute value moski 6 6,330 Jun-03-2019, 04:24 PM
Last Post: moski

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020