Еще вопрос по заполнению формы, правда на сей раз с другого сайта . Пользуясь полученными выше навыками, написал скрипт для автоматического входа на сайт и дальнейшего заполнения страницы "Добавить новость". Программа заходит на сайт, заполняет часть полей, но два поля упорно отказывается ("short_story" и "full_story"). Причем ошибок скрипт не выдает, но и поля не заполняет. Думаю виноват яваскрипт, но как его обойти?
Исходный текст формы (пришлось разбить на куски по типу):
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.
<form method=post name="entryform" id="entryform" onsubmit="document.getElementById('short_story').value = tinyMCE.get('short_story').getContent(); document.getElementById('full_story').value = tinyMCE.get('full_story').getContent(); if(document.entryform.title.value == '' || document.entryform.short_story.value == ''){alert('У вашей статьи должен быть хотя бы заголовок и краткая версия');return false}" action=""> <table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10" align="left" valign="top"><img src="/templates/new/images/dlet_artblock_11.gif" width="10" height="8" /></td>
<td align="left" valign="top" class="a_block_12"><img src="/templates/new/images/spacer.gif" width="1" height="8" /></td>
<td width="10" align="right" valign="top"><img src="/templates/new/images/dlet_artblock_13.gif" width="10" height="8" /></td>
</tr>
<tr>
<td width="10" align="left" valign="top"><img src="/templates/new/images/dlet_artblock_21.gif" width="10" height="23" /></td>
<td align="left" valign="top" class="a_block_22"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="17" align="left" valign="top"><img src="/templates/new/images/dlet_artblock_22_01.gif" width="17" height="23" /></td>
<td align="left" class="ntitle">Публикация новости на сайте</td>
<td width="17" align="right" valign="top"><img src="/templates/new/images/dlet_artblock_22_03.gif" width="17" height="23" /></td>
</tr>
</table></td>
<td width="10" align="right" valign="top"><img src="/templates/new/images/dlet_artblock_23.gif" width="10" height="23" /></td>
</tr>
<tr>
<td width="10" align="left" valign="top"><img src="/templates/new/images/dlet_artblock_31.gif" width="10" height="9" /></td>
<td align="left" valign="top" class="a_block_32"><img src="/templates/new/images/spacer.gif" width="1" height="9" /></td>
<td width="10" align="right" valign="top"><img src="/templates/new/images/dlet_artblock_33.gif" width="10" height="9" /></td>
</tr>
<tr>
<td width="10" align="left" valign="top" class="a_block_61"> </td>
<td align="left" valign="top" class="slink"><br />
<table width="99%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="110" height="25" nowrap="nowrap">Введите заголовок:</td>
<td><input type="text" name="title" value="" maxlength="150" class="f_input" /></td>
</tr>
<tr>
<td height="25">Категория:</td>
<td><select name="catlist[]" id="category" onchange="onCategoryChange(this.value)" style="width:220px;height:73px;" multiple><option value="0"></option><option style="color: black" value="1" >Главная</option><option style="color: black" value="2" > Аудиокниги</option><option style="color: black" value="6" > Книги</option><option style="color: black" value="5" > Музыка</option><option style="color: black" value="4" > Видео</option><option style="color: black" value="3" > Анекдоты</option><option style="color: black" value="7" > Игрушки</option><option style="color: black" value="8" > Софт</option><option style="color: black" value="9" >Статьи</option><option style="color: black" value="10" >Упс</option></select></td>
</tr>
<tr>
<td>Краткое содержание:</td>
<td>
1. 2. 3. 4. 5. 6. 7. 8. 9.
<script type="text/javascript" src="engine/editor/jscripts/tiny_mce/tiny_mce_gzip.js"></script>
<script type="text/javascript">
tinyMCE_GZ.init({
plugins : "safari,advhr,advimage,emotions,inlinepopups,insertdatetime,media,searchreplace,print,contextmenu,paste,fullscreen,nonbreaking",
themes : 'advanced',
languages : 'ru',
disk_cache : false,
debug : false
});
</script>
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. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138.
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "exact",
theme : "advanced",
elements : "short_story,full_story",
language : "ru",
width : "98%",
height : "400",
plugins : "safari,advhr,advimage,emotions,inlinepopups,insertdatetime,media,searchreplace,print,contextmenu,paste,fullscreen,nonbreaking",
auto_focus : "short_story",
relative_urls : false,
convert_urls : false,
force_br_newlines : true,
forced_root_block : '',
force_p_newlines : false,
dialog_type : 'window',
extended_valid_elements : "div[align|class|style|id|title]",
// Theme options
theme_advanced_buttons1 : "cut,copy,|,paste,pastetext,pasteword,|,search,replace,|,outdent,indent,|,undo,redo,|,dle_upload,image,media,dle_mp,dle_mp3,emotions,|,dle_break,dle_page",
theme_advanced_buttons2 : "fontselect,fontsizeselect,|,sub,sup,|,charmap,advhr,|,insertdate,inserttime,|,nonbreaking,dle_quote,dle_hide,dle_code,|,visualaid",
theme_advanced_buttons3 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,dle_spoiler,|,link,dle_leech,|,forecolor,backcolor,|,removeformat,cleanup,|,code",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
plugin_insertdate_dateFormat : "%d-%m-%Y",
plugin_insertdate_timeFormat : "%H:%M:%S",
// Example content CSS (should be your site CSS)
content_css : "http://web-lib.info/engine/editor/css/content.css",
setup : function(ed) {
// Add a custom button
ed.addButton('dle_quote', {
title : 'Вставка цитаты',
image : 'http://web-lib.info/engine/editor/jscripts/tiny_mce/themes/advanced/img/dle_quote.gif',
onclick : function() {
// Add you own code to execute something on click
ed.execCommand('mceReplaceContent',false,'quote{$selection}/quote');
}
});
ed.addButton('dle_hide', {
title : 'Скрытый текст',
image : 'http://web-lib.info/engine/editor/jscripts/tiny_mce/themes/advanced/img/dle_hide.gif',
onclick : function() {
// Add you own code to execute something on click
ed.execCommand('mceReplaceContent',false,'[hide]{$selection}[/hide]');
}
});
ed.addButton('dle_code', {
title : 'Вставка исходного кода',
image : 'http://web-lib.info/engine/editor/jscripts/tiny_mce/themes/advanced/img/dle_code.gif',
onclick : function() {
// Add you own code to execute something on click
ed.execCommand('mceReplaceContent',false,'code{$selection}/code');
}
});
ed.addButton('dle_spoiler', {
title : '',
image : 'http://web-lib.info/engine/editor/jscripts/tiny_mce/themes/advanced/img/dle_spoiler.gif',
onclick : function() {
// Add you own code to execute something on click
ed.execCommand('mceReplaceContent',false,'');
}
});
ed.addButton('dle_break', {
title : 'Вставка разрыва между страницами',
image : 'http://web-lib.info/engine/editor/jscripts/tiny_mce/themes/advanced/img/dle_break.gif',
onclick : function() {
// Add you own code to execute something on click
ed.execCommand('mceInsertContent',false,'{PAGEBREAK}');
}
});
ed.addButton('dle_page', {
title : 'Вставка ссылки на страницу',
image : 'http://web-lib.info/engine/editor/jscripts/tiny_mce/themes/advanced/img/dle_page.gif',
onclick : function() {
var enterURL = prompt("Введите номер страницы", "1");
var enterTITLE = prompt("Введите описание ссылки", "");
if (enterURL == null ) enterURL = "1";
if (enterTITLE == null ) enterTITLE = "";
ed.execCommand('mceInsertContent',false,"[page="+enterURL+"]"+enterTITLE+"[/page]");
}
});
ed.addButton('dle_leech', {
title : 'Вставка защищенной ссылки',
image : 'http://web-lib.info/engine/editor/jscripts/tiny_mce/themes/advanced/img/dle_leech.gif',
onclick : function() {
var enterURL = prompt("Введите полный URL ссылки", "http://");
if (enterURL == null ) enterURL = "http://";
ed.execCommand('mceReplaceContent',false,"[leech="+enterURL+"]{$selection}[/leech]");
}
});
ed.addButton('dle_mp', {
title : 'Вставка видео (BB Codes)',
image : 'http://web-lib.info/engine/editor/jscripts/tiny_mce/themes/advanced/img/dle_mp.gif',
onclick : function() {
var enterURL = prompt("Введите полный URL ссылки", "http://");
if (enterURL == null ) enterURL = "http://";
ed.execCommand('mceInsertContent',false,"[video="+enterURL+"]");
}
});
ed.addButton('dle_upload', {
title : 'Загрузка файлов на сервер',
image : 'http://web-lib.info/engine/editor/jscripts/tiny_mce/themes/advanced/img/dle_upload.gif',
onclick : function() {
window.open('http://web-lib.info/engine/images.php?area=short_story&wysiwyg=yes&add_id=', '_Addimage', 'toolbar=0,location=0,status=0, left=0, top=0, menubar=0,scrollbars=yes,resizable=0,width=640,height=550');
}
});
ed.addButton('dle_mp3', {
title : '',
image : 'http://web-lib.info/engine/editor/jscripts/tiny_mce/themes/advanced/img/dle_mp3.gif',
onclick : function() {
var enterURL = prompt("Введите полный URL ссылки", "http://");
if (enterURL == null ) enterURL = "http://";
ed.execCommand('mceInsertContent',false,"[audio="+enterURL+"]");
}
});
}
});
</script>
1. 2. 3. 4. 5. 6. 7. 8. 9.
<textarea id="short_story" name="short_story" rows= 10 cols= 50 ></textarea></td>
</tr>
<tr>
<td>Полная новость:<br />(необязательно)</td>
<td> <br /><textarea id="full_story" name="full_story" rows= 10 cols= 50 ></textarea></td>
</tr>
<tr>
<td height="25" nowrap="nowrap">Ключевые слова<br />для облака тегов:</td>
<td><input type="text" name="tags" value="" maxlength="150" class="f_input" /></td>
</tr>
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.
<script type="text/javascript">
<!--
var item = null ;
if (document.getElementById) {
item = document.getElementById("category");
} else if (document.all) {
item = document.all["category"];
} else if (document.layers) {
item = document.layers["category"];
}
if (item) {
onCategoryChange(item.value);
}
// -->
</script>
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.
<tr>
<td>Код:</td>
<td><br /><span id="dle-captcha"><img src="/engine/modules/antibot.php" alt="Включите эту картинку для отображения кода безопасности" border="0"><br /><a onclick="reload(); return false;" href="#">обновить код</a></span></td>
</tr>
<tr>
<td>Введите код:</td>
<td><input type="text" name="sec_code" id="sec_code" style="width:115px" class="f_input" /></td>
</tr>
<tr>
<td width="110"> </td>
<td><input type="checkbox" name="allow_comm" value="1" checked>Разрешить комментарии <input type="checkbox" name="allow_main" value="1" checked>Публиковать на главной<br><input type="checkbox" name="approve" value="1" checked> Опубликовать новость на сайте<br><input type="checkbox" name="allow_rating" value="1" checked> Разрешить рейтинг статьи</td>
</tr>
<tr>
<td width="110"> </td>
<td><input class="bbcodes_poll" type="submit" name="add" value="отправить" />
<input class="bbcodes_poll" type="button" name="nview" onclick="preview()" value="просмотр" /></td>
</tr>
</table>
</td>
<td width="10" align="right" valign="top" class="a_block_63"> </td>
</tr>
<tr>
<td width="10" align="left" valign="top"><img src="/templates/new/images/dlet_artblock_71.gif" width="10" height="7" /></td>
<td align="left" valign="top" class="a_block_72"><img src="/templates/new/images/spacer.gif" width="1" height="7" /></td>
<td width="10" align="right" valign="top"><img src="/templates/new/images/dlet_artblock_73.gif" width="10" height="7" /></td>
</tr>
<tr>
<td width="10" align="left" valign="top"><img src="/templates/new/images/dlet_artblock_81.gif" width="10" height="14" /></td>
<td align="left" valign="top" class="a_block_82"> </td>
<td width="10" align="right" valign="top"><img src="/templates/new/images/dlet_artblock_83.gif" width="10" height="14" /></td>
</tr>
</table>
<br /><input type="hidden" name="mod" value="addnews" /><input type="hidden" name="vuzvjypm" value="88ab990097183bbb632b2e06881b3b07" /></form>
И программный код:
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. 52.
Sub web_lib_info()
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://web-lib.info/addnews.html"
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1 , Now)
Loop
' проверяем залогинились ли?
need_login = False
If IE.document.forms( 0 ).Elements( 0 ).Name = "login_name" Then
need_login = True
End If
If need_login = True Then
With IE.document.forms( 0 )
.Elements("login_name").Value = "valera"
.Elements("login_password").Value = "script"
.submit
End With
Do While IE.Busy
Application.Wait DateAdd("s", 1 , Now)
Loop
End If
With IE.document.forms( 1 )
.Elements("title").Value = "Заголовок"
.Elements("short_story").Value = "Короткий текст"
.Elements("full_story").Value = "Полный текст"
.Elements("tags").Value = "Ключевые слова"
.Elements("catlist[]").Value = "2"
End With
' Wait while IE re-loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1 , Now)
Loop
' Clean up
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub
И второй вопрос - можно ли как-то с помощью VB вставить в эти два поля текст, сгенеренный HTML? Ну то есть по аналогии "нажать на кнопочку HTML в форме, и вставить данные".
Всем спасибо!
|