Skip to content

Commit 594cfb2

Browse files
one page scrapped
1 parent f11155b commit 594cfb2

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import requests, os
33
from bs4 import BeautifulSoup as bs
4+
import pandas as pd
45

56
try: os.mkdir('Scrapped')
67
except: pass
@@ -9,10 +10,29 @@
910
req = requests.get(link)
1011
soup = bs(req.content, 'html5lib')
1112

13+
data = {}
1214
table = soup.findAll('table', attrs = {'class':'table'})[0]
13-
for i in table:
14-
tr = table.findAll('tr')
15+
tr = table.findAll('tr')
1516

16-
for j in tr:
17-
print(j.text.strip()) # append this in list
18-
# and update in new dict above list
17+
for i, j in enumerate(tr):
18+
lst = []
19+
if i == 0:
20+
th = j.findAll('th')
21+
for m in th:
22+
lst.append(m.text.strip())
23+
else:
24+
td = j.findAll('td')
25+
for n in td:
26+
lst.append(n.text.strip())
27+
data.update({i : lst})
28+
29+
df = pd.DataFrame.from_dict(
30+
data,
31+
orient='index'
32+
)
33+
34+
df.to_csv(
35+
'Scrapped/Forms, Searching & Pagination.csv',
36+
index = False,
37+
encoding='utf-8'
38+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
0,1,2,3,4,5,6,7,8
2+
Team Name,Year,Wins,Losses,OT Losses,Win %,Goals For (GF),Goals Against (GA),+ / -
3+
Boston Bruins,1990,44,24,,0.55,299,264,35
4+
Buffalo Sabres,1990,31,30,,0.388,292,278,14
5+
Calgary Flames,1990,46,26,,0.575,344,263,81
6+
Chicago Blackhawks,1990,49,23,,0.613,284,211,73
7+
Detroit Red Wings,1990,34,38,,0.425,273,298,-25
8+
Edmonton Oilers,1990,37,37,,0.463,272,272,0
9+
Hartford Whalers,1990,31,38,,0.388,238,276,-38
10+
Los Angeles Kings,1990,46,24,,0.575,340,254,86
11+
Minnesota North Stars,1990,27,39,,0.338,256,266,-10
12+
Montreal Canadiens,1990,39,30,,0.487,273,249,24
13+
New Jersey Devils,1990,32,33,,0.4,272,264,8
14+
New York Islanders,1990,25,45,,0.312,223,290,-67
15+
New York Rangers,1990,36,31,,0.45,297,265,32
16+
Philadelphia Flyers,1990,33,37,,0.412,252,267,-15
17+
Pittsburgh Penguins,1990,41,33,,0.512,342,305,37
18+
Quebec Nordiques,1990,16,50,,0.2,236,354,-118
19+
St. Louis Blues,1990,47,22,,0.588,310,250,60
20+
Toronto Maple Leafs,1990,23,46,,0.287,241,318,-77
21+
Vancouver Canucks,1990,28,43,,0.35,243,315,-72
22+
Washington Capitals,1990,37,36,,0.463,258,258,0
23+
Winnipeg Jets,1990,26,43,,0.325,260,288,-28
24+
Boston Bruins,1991,36,32,,0.45,270,275,-5
25+
Buffalo Sabres,1991,31,37,,0.388,289,299,-10
26+
Calgary Flames,1991,31,37,,0.388,296,305,-9
27+
Chicago Blackhawks,1991,36,29,,0.45,257,236,21

0 commit comments

Comments
 (0)