Skip to content

Instantly share code, notes, and snippets.

@Innarticles
Last active August 25, 2018 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Innarticles/940cc3f86764784691dbf4d15c4e35a4 to your computer and use it in GitHub Desktop.
Save Innarticles/940cc3f86764784691dbf4d15c4e35a4 to your computer and use it in GitHub Desktop.
url = "http://integrity.ng/index.php/units/browse"
from bs4 import BeautifulSoup
import requests
import csv
# Main Coding Sectio
start = 1
with open("Units.csv", 'wb') as save:
while True:
try:
writer = csv.writer(save, delimiter=',')
nxt = (url + "/"+ str(start))
print (nxt)
r = requests.get(nxt)
soup = BeautifulSoup(r.content, 'html.parser')
table = soup.find("table",{"class": "table table-striped m-b-none"})
table_rows = table.find_all('tr')
for each_row in table_rows[1:]:
row = each_row.get_text()
writer.writerow(row.splitlines())
print((row.splitlines()))
except Exception as e:
print(e)
break
start += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment