I need to web scrape url and save it to excel like image I uploaded
but I don't no what is wrong with my code
I get only one row in my excel file. Help me plz.
import requests
from bs4 import BeautifulSoup
import csv
url='http://www.kobis.or.kr/kobis/business/mast/thea/findTheaterInfoList.do'
for i in range(10):
payload={'pageIndex':i}
r=requests.post(url, params=payload)
soup=BeautifulSoup(r.text, 'html.parser')
table=soup.find('table')
rows=table.find('tbody').find_all('tr')
for j in range(len(rows)):
col=rows[j].find_all('td')
result=[]
for item in col:
result.append(item.get_text())
with open(r"C:\Users\lwt04\Desktop\TheaterInfo.csv","w",newline='') as out:
theater = csv.writer(out)
theater.writerow(['City','District','Code','Name','NumScreen','NumSeats', 'Permanent', 'Registered', 'License','OpenDate','Run'])
with open(r"C:\Users\lwt04\Desktop\TheaterInfo.csv","a",newline='') as out:
theater = csv.writer(out)
theater.writerow(result)