from seleniumwire import webdriver
import time
print("Init...")
password = "fucku"
def rand_name():
return "ㅇㅇ"
def rand_subject():
return "테스트"
def rand_content():
return "테스트"
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36")
driver = webdriver.Chrome('./chromedriver',chrome_options=chrome_options)
driver.implicitly_wait(3)
# 셀레니움 와이어로 헤더 변경
def interceptor(request):
del request.headers['Referer']
del request.headers['User-Agent']
request.headers['Referer'] = 'https://gall.dcinside.com/board/write/?id=pridepc_new4'
request.headers['User-Agent'] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'
driver.request_interceptor = interceptor
# 접속
driver.get('https://gall.dcinside.com/board/write/?id=pridepc_new4')
# 로그인 정보 작성
driver.find_element_by_id('name').clear()
driver.find_element_by_id('name').send_keys(rand_name())
driver.find_element_by_id('password').clear()
driver.find_element_by_id('password').send_keys(password)
# 제목 작성
driver.find_element_by_id('subject').send_keys(rand_subject())
# 내용 작성
driver.switch_to_frame(driver.find_element_by_id('tx_canvas_wysiwyg'))
driver.find_element_by_class_name('tx-content-container').send_keys(rand_content())
# 포스트
driver.switch_to_default_content()
driver.find_element_by_xpath("//button[@type='image'][@class='btn_blue btn_svc write']").click()
크롬드라이버 버전은 87.0.4280.141 가 아니고 87.0.4280.88 이긴 한데 이건 상관 없을거 같고...
리퍼러랑 유저 에이전트 디버그 콘솔에서 포스트 할때랑 동일하게 넣었는데도 안되네
???
왜저렇게 한거지 저 인터셉터 제대로 동작하는거 맞음? 애초에 유저에이전트가 잘 안들어간거 아님?
https://stackoverflow.com/questions/29916054/change-user-agent-for-selenium-web-driver
이거보고 Options 써서 해봐라 근데 requests 안쓰고 셀레니움 쓰는 이유는 뭐임
웹을 잘 모르니깐...
리퀘스트 예제가 잘 안보이던데 혹시 추천좀 해줄 수 있어?
아 이제보니 크롬옵션에서 짤렸네 확인해봄
크롬 옵션 유저에이전트 인자 제대로 줘도 안되네 원래 이렇게 썼다가 나중에 빼먹은듯
headless 라 그런가
그거랑 헤더 없는거랑 다름
그건 나도 알지 ㅋㅋㅋㅋㅋ
내말은 오류 코드가
디시인사이드 비공식 확장 프로그램이 실행된 경우, 오류가 발생할 수 있습니다. (오류접수코드: NZEWMZQ)} (Session info: chrome=87.0.4280.141) 이런식이길래 함 headless 때 보고 했는데도 안되네
멍청하지 않음 ㅜㅜ 걍 웹쪽만 모름