혼자 고민해보기_ 개발/TIL (Today I Learned)
20230906(수)_ 최종프로젝트 진행
nuri-story
2023. 9. 6. 21:54
금일 달성 항목
1) incruit 크롤링 재시도 및 완료
문제 해결 과정 1 - incruit 크롤링
[문제]
이전에 크롤링한 데이터에서 직무요소가 빠져있어서 다시 크롤링해야하는 상황이었습니다. 현재 상세페이지에서 job,company에 대한 데이터를 모두 가져오고 있었는데 상세페이지에는 직무와 관련된 데이터가 없었습니다.
그래서 어쩔 수 없이 job데이터는 상세페이지가 아닌 리스트 영역에서 다시 파싱하는 방향으로 코드를 모두 수정했습니다.
그때 크롤링한 데이터가 하나가 아닌 리스트 전체 60 개를 모두 불러와서 표현해주어서
compay 1개 jobposting 60개 이런 식으로 크롤링이 되어서 필터링을 해주어야하는 상황이었습니다.
그리고 그 외에도 잡다한 오류들이 많았습니다.
[시도 및 해결]
// 인증 번호
@Column({
default: 'false',
type: 'varchar',
length: 10,
comment: '인증번호',
})
verificationCode: string;
왜 jobposting이 많나 했더니 하나의 jobposting id가 2개 정도 중복되서 들어오는 이슈가 있었음
채용공고 파싱
jobParsing(page, _companyId) {
const $ = cheerio.load(page);
const $jobList = $('.c_row');
const jobs = [];
$jobList.each((idx, node) => {
const companyLink = $(node).find('.cpname');
const companyId = Number(companyLink.attr('href').split('/').pop());
if (companyId !== _companyId) {
return;
}
파싱하는 영역
async incruitCrawling() {
console.time('코드 실행시간');
const totalPage = 1; // 크롤링할 페이지
const jobInfo = [];
const companyInfo = [];
for (let i = 1; i <= totalPage; i++) {
const jobpostingUrl = `https://job.incruit.com/jobdb_list/searchjob.asp?ct=3&ty=1&cd=149&page=${i}`;
const jobpostingContent = await this.getAxiosData(jobpostingUrl);
const $ = cheerio.load(jobpostingContent);
const jobLinks = $('li.c_col .cell_mid .cl_top a');
for (const jobLink of jobLinks) {
const jobDetailUrl = $(jobLink).attr('href');
const companyContent = await this.getAxiosData(jobDetailUrl);
const jobContent = await this.getAxiosData(jobpostingUrl);
const companies = this.companyParsing(companyContent);
const jobs = this.jobParsing(jobContent, companies[0].id);
companyInfo.push(companies);
jobInfo.push(jobs);
// await this.delay(10000); // 각페이지 크롤링 후 5초 대기
}
}
const jobs = this.jobParsing(jobContent, companies[0].id);
채용정보를 파싱할때 위와같이 수정하여 중복을 없애고 각각의 모든 요소가 60개씩 들어오게 수정
[알게된 점]
아직도 코드가 전체적으로 이해가 안가서 다시 복습해서 공부해볼 생각입니다.