Skip to content

Commit

Permalink
user-agent 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hyejungg committed Jan 5, 2025
1 parent 9991c86 commit 88f8e05
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ const cheerio = require('cheerio');
const { NotFound } = require('../utils/errors');
const { ErrorMessage } = require('../utils/response');

const userAgents = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36',
'Mozilla/5.0 (Linux; U; Android 2.1; en-us; sdk Build/ERD79) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17',
];

const getRandomUserAgent = () => {
return userAgents[Math.floor(Math.random() * userAgents.length)];
};

const config = {
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
'User-Agent': getRandomUserAgent(),
'Accept':
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive',
},
validateStatus: function (status) {
return status >= 200 && status < 300;
Expand Down

0 comments on commit 88f8e05

Please sign in to comment.