Here's link for scraping : http://5000best.com/websites/Games/
I tried almost everything I can. I'm a beginner in web scraping.
My code :
import requests
from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.error import URLError
from bs4 import BeautifulSoup
import pandas as pd
import csv
try:
html = urlopen("http://5000best.com/websites/Games/")
except HTTPError as e:
print(e)
except URLError as u:
print(u)
else:
soup = BeautifulSoup(html,"html.parser")
table = soup.findAll('div',{"id":"content"})[0]
tr = table.findAll(['tr'])[0:]
csvFile = open('games.csv','wt', newline='',encoding='utf-8')
writer = csv.writer(csvFile)
try:
for cell in tr:
th = cell.find_all('th')
th_data = [col.text.strip('\n') for col in th]
td = cell.find_all('td')
row = [i.text.replace('\n','') for i in td]
writer.writerow(th_data+row)
finally:
csvFile.close()
This code only scrape the first page of the table... I want all the pages. I inspected the web page but I didn't saw any url changes while toggling the page numbers, So it's completely dynamic.
