Spring
Project
롤문철(진행 중)

Lol Moon Chul

Lolmoonchul(롤문철) 프로젝트를 진행하면서 배운점을 정리하는 공간입니다.

배운점

Python Argv

파이썬 파일을 실행할 때 인자를 입력받는 방법이 있다.

test.py
import sys 
 
print(sys.argv)

위와 같은 파일이 있다고 가정했을 때

python test.py 1 2 3 4 5

이라고 실행하면 아래와 같은 실행 결과가 도출된다.

['test.py', '1', '2', '3', '4', '5']

Python Requests

파이썬에서 HTTP 요청을 보내는 방법이다.
headers와 data를 각각 json 형식으로 설정해서 보내줄 수 있는데, data는 post 요청의 body를 뜻한다.

url = "https://fow.kr/api_new_ajax.php"
data = {
  "action": "refresh",
  "name": refresh_user.name,
  "tag": refresh_user.tag,
  "sid": refresh_user.sid,
  "tried": tried
}
headers = {
  "Content-Type": "application/x-www-form-urlencoded",
  "X-Requested-With": "XMLHttpRequest",
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.71 Safari/537.36",
  "Referer": "https://fow.kr/find/dwg+kia-kr1",
  "Accept-Encoding": "gzip, deflate, br",
  "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7"
}
 
response = requests.post(url, data=data, headers=headers)

Python BeautifulSoup

  • find : 첫 번째 태그를 soup 형식으로 가져온다.
  • get : html 태그의 속성값을 가져온다.
  • find_all : 모든 태그를 list(soup) 형식으로 가져온다.

아래의 코드는 table 태그의 class가 tablesorter table_recent인 태그를 가져와서 tbody 태그를 가져오고, 그 안에 있는 모든 tr 태그를 가져온다. 그리고 그 tr 태그들을 반복하면서 img 태그의 src 속성값을 가져온다.

def get_table(soup) :
  table_class = soup.find('table', {'class': 'tablesorter table_recent'})
  table_body = table_class.find('tbody')
  tables = table_body.find_all('tr')
  for table in tables :
    img_src = table.find('img').get('src')

Burp Suite 사용

Proxy > Open Browser > Intercep is off를 클릭하면 다음과 같은 화면이 되는데

이는 Request를 수행하기 전에 Capture를 하는 기능이다.

Forward를 누르면 Reponse가 들어오고 Drop을 누르면 Request가 취소된다.

이를 통해서 Refresh 버튼을 누를 때 어떤 Request가 보내지는지 확인할 수 있었다.