import requests

from bs4 import BeautifulSoup

import pandas as pd

import re

login_url = 'https://www.jobplanet.co.kr/users/sign_in'

# email and password placeholders

email = '###'

password = '###'

LOGIN_INFO = {

'user[email]': email,

'user[password]': password,

'commit': '로그인'

}

session = requests.session()

res = session.post(login_url, data=LOGIN_INFO, verify=False)

res.raise_for_status()

result = []

def clean_str(text):

pattern = '([ㄱ-ㅎㅏ-ㅣ]+)'

text = re.sub(pattern=pattern, repl='', string=text)

pattern = '<[^>]*>'

text = re.sub(pattern=pattern, repl='', string=text)

pattern = '[^\w\s]'

text = re.sub(pattern=pattern, repl='', string=text)

text = text.replace('\r', '. ')

return text

last_page = 238

for idx in range(1, last_page):

url = f'https://www.jobplanet.co.kr/companies/1322/reviews/%ED%98%84%EB%8C%80%EC%97%94%EC%A7%80%EB%8B%88%EC%96%B4%EB%A7%81?page={idx}'

res = session.get(url)

res.raise_for_status()

soup = BeautifulSoup(res.text, 'html.parser')

count3, count4, count5 = 0, 0, 0

try:

for k in range(5):

reviewer_info = []

position = soup.select('.content_top_ty2 > span.txt1')[0 + count4].text

status = soup.select('.content_top_ty2 > span.txt1')[1 + count4].text

loc = soup.select('.content_top_ty2 > span.txt1')[2 + count4].text

day = soup.select('.content_top_ty2 > span.txt1')[3 + count4].text

star_rating = soup.select('.us_star_m > div.star_score')[0 + k]['style'][6:-1]

promotion = soup.select('.bl_score')[0 + count5]['style'][6:-1]

welfare = soup.select('.bl_score')[1 + count5]['style'][6:-1]

balance = soup.select('.bl_score')[2 + count5]['style'][6:-1]

culture = soup.select('.bl_score')[3 + count5]['style'][6:-1]

top = soup.select('.bl_score')[4 + count5]['style'][6:-1]

content = soup.select('h2.us_label')[0 + k].text

merit = soup.select('dl.tc_list > dd.df1 > span')[0 + count3].text

disadvantages = soup.select('dl.tc_list > dd.df1 > span')[1 + count3].text

df_tit = soup.select('dl.tc_list > dd.df1 > span')[2 + count3].text

reviewer_info = [position, status, loc, day, star_rating, promotion, welfare, balance, culture, top, clean_str(content), clean_str(merit), clean_str(disadvantages), clean_str(df_tit)]

result.append(reviewer_info)

count3 += 3

count4 += 4

count5 += 5

print(f"pass :{idx}-{k}")

except:

print(f"fail :{idx}")

colname = ['직무', '상황', '지역', '작성일', '총점', '승진 기회 및 가능성', '복지 및 급여', '업무와 삶의 균형', '사내문화', '경영진', '총평', '장점', '단점', '바라는점']

df = pd.DataFrame(result, columns=colname)

from google.colab import files

df.to_excel("jobplanet_기업명.xlsx")

files.download('jobplanet_기업명.xlsx')

print(result)