티스토리 뷰
테스트 환경
- Ubuntu 18.04
- Python 2.7
사전 설정
- sudo pip install selenium
- sudo pip install selenium-requests
- Chrome 및 Chrome Webdriver 설치
예제
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/usr/bin/python
from seleniumrequests import Chrome
from selenium import webdriver
PAGE_LIST = {
'entry':'http://192.168.10.18:5000/entry.jsp',
}
# create a session
def CreateSession():
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument("disable-gpu")
options.add_argument("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36")
# which chromedriver => /usr/sbin/chromedriver
chrome = Chrome('chromedriver', chrome_options=options)
return chrome
# POSTRequest
def POSTRequestAPI(session, url, sessid, arg):
#headers = {'Content-Type' : 'application/json; charset=utf-8'}
response = session.request('POST', url, data=arg)
print response.content
session.quit()
# GETRequest
def GETRequestAPI(session, url, sessid, arg):
#headers = {'Content-Type' : 'application/json; charset=utf-8'}
r = session.request('GET', url, params=arg)
print r.content
session.quit()
# main function
def main():
s = CreateSession()
if s == None:
return False
arg = dict()
arg['page'] = '\"sample\"'
arg['id'] = '1234'
#GETRequestAPI(s, PAGE_LIST['entry'], 'dfklvhdfgjikhgiuesrnjikfthuisedriuearui', arg)
POSTRequestAPI(s, PAGE_LIST['entry'], 'dfklvhdfgjikhgiuesrnjikfthuisedriuearui', arg)
if __name__ == '__main__':
main()
|
cs |
- CreateSession : headless 옵션으로 Chrome webdriver 생성
- POSTRequestAPI : 해당 URL 페이지에 POST 메소드로 인자를 넘긴다.
- GETRequestAPI : 해당 URL 페이지에 GET 메소드로 인자를 넘긴다.
메소드 별로 Request해서 데이터를 얻는 예제를 찾는데 원하는 예제가 없었다.
'Web' 카테고리의 다른 글
[React] 렌더링 최적화 (0) | 2022.04.12 |
---|---|
[React] test code (0) | 2022.04.01 |
[Python] requests 모듈 (0) | 2018.10.02 |
Blind SQL Injection 실습 정리 (0) | 2017.05.16 |
mysql 설치 후, mysql 접속 안 될 때 (0) | 2017.05.15 |
댓글