Необходимо на сайте (myspace.com) заполнить поле и нажать кнопочку с подтверждением. Со всем разобрался, но форма не заполняется нивкакую. Ниже я представлю кусок страницы, который тут полезен будет и дальше объясню, что я делал. | Код | . // Refreshes the CAPTCHA and any entered text. function RefreshCI() { // Stops the timer during execution of this methods to // prevent multiple requests. clearTimeout(timerID); // Set the answer text box to nothing. var answer = document.getElementById('ctl00_ctl00_ctl00_cpMain_cpMain_cpfMainBody_VerificationPanel_captcha_captchaResponseTextBox'); answer.value = '';
var captcha = document.getElementById('ctl00_ctl00_ctl00_cpMain_cpMain_cpfMainBody_VerificationPanel_captcha_captchaImage'); if (i > 0) { captcha.src = 'http://security.myspace.com/captcha/captcha.aspx?SecurityToken=24094092E17846F786149416F6D797AA&dl=2&ho=1&uc=1&r=' + i; } i++; timerID = self.setTimeout("RefreshCI()", secs * 1000);
}
function UpdateChallengeToken() { var dynamicField = document.getElementById("recaptcha_challenge_field"); var challengeToken = document.getElementById("ctl00_ctl00_ctl00_cpMain_cpMain_cpfMainBody_VerificationPanel_captcha_reCaptchaChallengeToken"); challengeToken.value = dynamicField.value; timerID = self.setTimeout("RefreshCI()", secs * 1000); }
var smsVerificationPopupWindow;
function openSMSVerificationPopup(){ if (smsVerificationPopupWindow == null || smsVerificationPopupWindow == undefined || smsVerificationPopupWindow.closed ) { smsVerificationPopupWindow = window.open( 'http://profileedit.myspace.com/index.cfm?fuseaction=accountSettings.smsVerificationPopup&myToken=4483a7ae-669f-4709-aa40-b33ffece372a', 'smsVerificationPopupWindow', 'width=700, height=400, resizeable=no, menubar=0,toolbar=0, titlebar=no, status=no, scroll bars=no, location=no'); } else { smsVerificationPopupWindow.focus(); } } </script>
<div class="captcha"> <img id="ctl00_ctl00_ctl00_cpMain_cpMain_cpfMainBody_VerificationPanel_captcha_captchaImage" src="http://security.myspace.com/captcha/captcha.aspx?SecurityToken=24094092E17846F786149416F6D797AA&dl=2&ho=1&uc=1" style="border-width:0px;" /> <a href="javascript:RefreshCI();"> <img src="http://x.myspace.com/images/icons/refreshicon2.jpg" border="0" contenteditable="false" id="IMG2" alt="Refresh CAPTCHA" /></a> <br /> <br /> <div id="ctl00_ctl00_ctl00_cpMain_cpMain_cpfMainBody_VerificationPanel_captcha_divSickOfCaptchas"> <span style="padding: 8px 8px 8px 8px; margin-bottom: 5px; background-color: #6698cb"> <strong>New!</strong> Sick of CAPTCHAs? <a href="javascript:openSMSVerificationPopup()"> Click here!</a></span> </div> <br /> Please enter the text from the image above: <br /> The letters are not case-sensitive. <br /> Do not type spaces between the numbers and letters. <br /> <br /> <input name="ctl00$ctl00$ctl00$cpMain$cpMain$cpfMainBody$VerificationPanel$captcha$captchaResponseTextBox" type="text" maxlength="50" id="ctl00_ctl00_ctl00_cpMain_cpMain_cpfMainBody_VerificationPanel_captcha_captchaResponseTextBox" /><br /> <span id="ctl00_ctl00_ctl00_cpMain_cpMain_cpfMainBody_VerificationPanel_captcha_captchaCustomValidator" style="color:Red;display:none;">Incorrect verification code. Please try again.</span> <span id="ctl00_ctl00_ctl00_cpMain_cpMain_cpfMainBody_VerificationPanel_captcha_rqfValTbxBoxCha" OnServerValidate="ValidateCaptcha" style="color:Red;visibility:hidden;">Please enter the image text.</span> <input type="hidden" name="ctl00$ctl00$ctl00$cpMain$cpMain$cpfMainBody$VerificationPanel$captcha$reCaptchaChallengeToken" id="ctl00_ctl00_ctl00_cpMain_cpMain_cpfMainBody_VerificationPanel_captcha_reCaptchaChallengeToken" /> </div> <br /> </div> </div>
|
Вот соответствующая часть окна  В поле необходимо ввести текст с капчи. Как и откуда он берется если надо будет - потом подробнее расскажу. Факт - он есть. Факт - у меня получается нажать на кнопку Add to Friends. Но вот заполнить поле не получается. Делал сначала просто тупо | Код | // Пробуем получить html-документ CComPtr<IDispatch> pDispDoc; m_spWebBrowser->get_Document( &pDispDoc ); CComQIPtr<IHTMLDocument2> pHtmlDoc( pDispDoc );
//Получаем все элементы IHTMLElementCollection *pLinksCollection = NULL; pHtmlDoc->get_all( &pLinksCollection ); LPSTR lpstrLink; long iLength = 0; pLinksCollection->get_length( &iLength ); VARIANT varName, varIndex; LPCTSTR lpctstrUrl = A2W( lpstrUrl ); LPSTR lpstrSpecLink; LPSTR lpstrAnswer; //Ищем, есть ли кепча на странице. Если есть, запрашиваем ввод for ( int i = 0; i < iLength; i++ ) { varName.vt = VT_I4; varName.lVal = i; varIndex.vt = VT_I4; varIndex.lVal = 1; IDispatch *pdisp2 = NULL;
if ( pLinksCollection->item( varName, varIndex, &pdisp2 ) != S_OK ) break;
if ( pdisp2 == NULL ) break;
IHTMLElement *pItem = NULL; pdisp2->QueryInterface( IID_IHTMLElement, ( LPVOID* ) &pItem ); if ( pItem == NULL ) break;
VARIANT varRet; pItem->getAttribute( L"src", 0, &varRet ); if ( ( varRet.bstrVal != NULL ) && ( varRet.bstrVal != BSTR( 0xcccccccc ) ) ) { LPSTR lpstrLink = OLE2A( varRet.bstrVal ); if ( strstr( OLE2A( varRet.bstrVal ), "security.myspace.com/captcha/captcha.aspx?" ) ) { //загружаем длл HMODULE lib2 = LoadLibraryA("C:\\dllCaptcha.dll"); //формируем специальную ссылку lpstrSpecLink = new char[strlen(lpstrLink)+4]; LPSTR lpstrGoodEnd = LPSTR( "&r=" );
int ii = 0; for( ii = 0; ii < strlen(lpstrLink); ii++ ) lpstrSpecLink[ii] = lpstrLink[ii]; for(ii; ii < strlen(lpstrLink) + strlen(lpstrGoodEnd); ii++ ) lpstrSpecLink[ii] = lpstrGoodEnd[ii-strlen(lpstrLink)]; lpstrSpecLink[ii] = '\0'; //запускаем фрейм MessageBeep( 100 ); lpstrAnswer = new char[20];//ответ groupinfo group=groupinfo(lpstrSpecLink, lpstrAnswer ); if ( lib2 ) { getCaptchaCode pgetCaptchaCode = (getCaptchaCode)GetProcAddress( lib2, "getCaptchaCode" ); pgetCaptchaCode(group); lpstrAnswer = group.captchaValue; } //выгружаем длл FreeLibrary( lib2 );
//cpMain_cpMain_cpfMainBody_VerificationPanel_captcha_captchaResponseTextBox //пытаемся засунуть теккст кепчи в поле for ( int j = 0; j < iLength; j++ ) { varName.vt = VT_I4; varName.lVal = j; varIndex.vt = VT_I4; varIndex.lVal = 1; IDispatch *pdisp2 = NULL;
if ( pLinksCollection->item( varName, varIndex, &pdisp2 ) != S_OK ) break;
if ( pdisp2 == NULL ) break;
IHTMLElement *pItem = NULL; pdisp2->QueryInterface( IID_IHTMLElement, ( LPVOID* ) &pItem ); if ( pItem == NULL ) break; VARIANT varRet2; HRESULT hr = pItem->getAttribute( L"id", 0, &varRet2 ); if ( ( varRet2.bstrVal != NULL ) && ( varRet2.bstrVal != BSTR( 0xcccccccc ) ) ) { LPSTR lpstrInputID = OLE2A( varRet2.bstrVal ); if ( strstr( lpstrInputID, "cpfMainBody_VerificationPanel_captcha_captchaResponseTextBox" ) ) { VARIANT setText; setText.bstrVal = A2OLE( lpstrAnswer ); pItem->setAttribute( L"value", setText ); break; } } } } } }
|
Ну собственно ничего в поле не вставляется. Я погуглил, нашел что вроде можно это сделать с помощью POST, типа вот так | Код | //делаем POST postDataString = new char[strlen(postDataStringBase) + strlen(lpstrAnswer)]; strcpy( postDataString, postDataStringBase ); strcat( postDataString, lpstrAnswer ); //заполняем поле ввода и отсылаем данные на сервер CComVariant postData(postDataString); int len = strlen(postDataString); postData.vt = VT_ARRAY; postData.parray = SafeArrayCreateVector(VT_UI1, 0, len); void HUGEP* safeData; SafeArrayAccessData(postData.parray, &safeData); memcpy(safeData, postDataString, len); SafeArrayUnaccessData(postData.parray);
CComVariant vHeaders(0); BSTR bstrHeaders = NULL; bstrHeaders = SysAllocString(L"Content-Type: application/x-www-form-urlencoded"); V_VT(&vHeaders) = VT_BSTR; V_BSTR(&vHeaders) = bstrHeaders;
CComVariant targetFrame( L"_self" ); CComVariant vNull;
m_spWebBrowser->Navigate( A2OLE(lpstrUrl), &vNull, &targetFrame, &postData, &vHeaders);
|
Тоже нету результата. Собственно теперь вопрос, как же это сделать? Есть впринципе возможность еще. это в коде страницы если answer.value = ''; сделать answer.value = 'MyText'; то там будет нужный мне текст. но как туда засунуть что-то я не знаю((( Хелп.
|