pecsenye Posted September 1, 2019 Posted September 1, 2019 (edited) Hello, i had a good script but i can't find it... The task: 1. Open an website 2. Save text it will be a large txt file with a lot of redundant data. I would like to keep important data, so delete unnecessary data. For example this script is very good, save txt file remove blank lines, but i like NewTest.txt included only some data. expandcollapse popup#include <File.au3> #include <Array.au3> $oIE = ObjCreate("Shell.Explorer.2") GUICreate("Browser", 0, 0, 10, 10) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 10, 10) GUISetState(@SW_HIDE); $oIE.navigate("URL") ; <-- your url here Do Sleep(100) Until Not $oIE.Busy ConsoleWrite($oIE.document.body.innerText) MsgBox(0, "", $oIE.document.body.innerText) $file = FileOpen(@ScriptDir & '\Name.txt', 2) FileWrite($file, $oIE.document.body.innerText) Global $aLines _FileReadToArray("Name.txt", $aLines) For $i = $aLines[0] To 1 Step -1 If $aLines[$i] = "" Then _ArrayDelete($aLines, $i) EndIf Next _FileWriteFromArray("NewTest.txt", $aLines, 1) FileClose($file) Thank you for helping! Edited September 1, 2019 by pecsenye
FrancescoDiMuro Posted September 1, 2019 Posted September 1, 2019 @pecsenye We help people with their scripts, so, come with a runnable script if you have any problem. By the way 9 minutes ago, pecsenye said: Open an website Use _IE* functions, and 10 minutes ago, pecsenye said: Save source code an txt file Use _IE functions. Then, use File* functions to read the file in a variable, remove what is not necessary, and write the content back always with those functions Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
pecsenye Posted September 1, 2019 Author Posted September 1, 2019 (edited) Sorry, I corrected the original post with code. Edited September 1, 2019 by pecsenye
Developers Jos Posted September 1, 2019 Developers Posted September 1, 2019 1 hour ago, pecsenye said: but I would like to find any keywords Look at the StringRegExp() in the helfile for how you can do that. You will have to be a lot more specific with examples in case you need help when it isn't working! Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
pecsenye Posted September 1, 2019 Author Posted September 1, 2019 (edited) This is it! Blank lines removed, its very good! Last problem: NewTest.txt included all data without blank lines. But i like NewTest.txt included only some data. (which is important to me) Original post edited full code. Global $aLines _FileReadToArray("Name.txt", $aLines) For $i = $aLines[0] To 1 Step -1 If $aLines[$i] = "" Then _ArrayDelete($aLines, $i) EndIf Next _FileWriteFromArray("NewTest.txt", $aLines, 1) Edited September 1, 2019 by pecsenye
Developers Jos Posted September 1, 2019 Developers Posted September 1, 2019 Like I said: 1 hour ago, Jos said: You will have to be a lot more specific with examples in case you need help when it isn't working! There is no way anybody can help you with the provided information. for starters: post a runnable script that contains everything to replicate your issue. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
pecsenye Posted September 1, 2019 Author Posted September 1, 2019 Here is code working code: NewTest.txt included all data without blank lines. But i like NewTest.txt included only some data. (which is important to me) expandcollapse popup#include <File.au3> #include <Array.au3> $oIE = ObjCreate("Shell.Explorer.2") GUICreate("Browser", 0, 0, 10, 10) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 10, 10) GUISetState(@SW_HIDE); $oIE.navigate("URL") ; <-- your url here Do Sleep(100) Until Not $oIE.Busy ConsoleWrite($oIE.document.body.innerText) MsgBox(0, "", $oIE.document.body.innerText) $file = FileOpen(@ScriptDir & '\Name.txt', 2) FileWrite($file, $oIE.document.body.innerText) Global $aLines _FileReadToArray("Name.txt", $aLines) For $i = $aLines[0] To 1 Step -1 If $aLines[$i] = "" Then _ArrayDelete($aLines, $i) EndIf Next _FileWriteFromArray("NewTest.txt", $aLines, 1) FileClose($file)
Developers Jos Posted September 1, 2019 Developers Posted September 1, 2019 (edited) 3 minutes ago, pecsenye said: Here is code working code: Doubt that. 3 minutes ago, pecsenye said: $oIE.navigate("URL") ; <-- your url here I also do not see and StringRegEx() in there. Edited September 1, 2019 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
mikell Posted September 1, 2019 Posted September 1, 2019 It seems that you misunderstood what Jos asked for (about "runnable script"). Please provide an url to test and work with, and an overview of the expected result BTW there are probably other (and faster) ways to do that, but no possible help with so little information
Nine Posted September 1, 2019 Posted September 1, 2019 Also, if you look in help file, under File Management, you will see there is a warning regarding the use of handle and file name in the same script : Note: Do not mix filehandles and filenames, i.e., don't FileOpen() a file and then use a filename in this function. Use either filehandles or filenames in your routines, not both! “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
pecsenye Posted September 1, 2019 Author Posted September 1, 2019 (edited) Ok, sorry... This is working code, with exemple url. expandcollapse popup#include <File.au3> #include <Array.au3> $oIE = ObjCreate("Shell.Explorer.2") GUICreate("Browser", 0, 0, 10, 10) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 10, 10) GUISetState(@SW_HIDE); $oIE.navigate("https://www.autoitscript.com/site/code/") ; <-- your url here Do Sleep(100) Until Not $oIE.Busy ConsoleWrite($oIE.document.body.innerText) MsgBox(0, "", $oIE.document.body.innerText) $file = FileOpen(@ScriptDir & '\Name.txt', 2) FileWrite($file, $oIE.document.body.innerText) Global $aLines _FileReadToArray("Name.txt", $aLines) For $i = $aLines[0] To 1 Step -1 If $aLines[$i] = "" Then _ArrayDelete($aLines, $i) EndIf Next _FileWriteFromArray("NewTest.txt", $aLines, 1) FileClose($file) After code run, I open NewText.txt and I see this: expandcollapse popupThis website uses cookies to ensure you get the best experience on our website. Learn more Got it! Forum Wiki AutoIt AutoIt Overview Downloads Graphics Documentation AutoIt Editor Editor Overview Editor Downloads Editor Documentation Software AutoIt Tools OSD Background GImageX Logoff Screensaver VDI Optimizer Code Blog Contact Us Select Page Forum Wiki AutoIt AutoIt Overview Downloads Graphics Documentation AutoIt Editor Editor Overview Editor Downloads Editor Documentation Software AutoIt Tools OSD Background GImageX Logoff Screensaver VDI Optimizer Code Blog Contact Us Home » Code Code (adsbygoogle = window.adsbygoogle || []).push({}); Overview Here are some C++ source code samples from various projects of mine. Most are free to use but check any license files that accompany the downloads for details. All code was created in Microsoft Visual C (6 and 7) but most would probably compile under mingw32 as well. Hints and tips are always welcome. Mail me here. Compression Code Download LZ77/LZSS Compression and decompression code. There are many versions here from really basic to fairly complicated. The later versions of the code use a LZ77 compression with huffman backend. Other Articles You May Like AutoIt Scripting Language Logoff Screensaver (adsbygoogle = window.adsbygoogle || []).push({}); News AutoIt v3.3.14.5 Released Site Navigation Forum Wiki AutoItAutoIt Overview Downloads Graphics Documentation AutoIt EditorEditor Overview Editor Downloads Editor Documentation SoftwareAutoIt Tools OSD Background GImageX Logoff Screensaver VDI Optimizer Code Blog Contact Us Forum Wiki AutoIt AutoIt Editor Software Code Blog Contact Us Twitter RSS Copyright ©2019 AutoIt Consulting Ltd Privacy - Cookies - Ts&Cs var wpcf7 = {"apiSettings":{"root":"https:\/\/www.autoitscript.com\/site\/wp-json\/contact-form-7\/v1","namespace":"contact-form-7\/v1"},"recaptcha":{"messages":{"empty":"Please verify that you are not a robot."}},"cached":"1"}; var monarchSettings = {"ajaxurl":"https:\/\/www.autoitscript.com\/site\/wp-admin\/admin-ajax.php","pageurl":"https:\/\/www.autoitscript.com\/site\/code\/","stats_nonce":"53bf8cd9c7","share_counts":"4cbacbd174","follow_counts":"10737c390b","total_counts":"ce08f67b26","media_single":"4829f770c3","media_total":"f32ca8701b","generate_all_window_nonce":"ecc9d55eda","no_img_message":"No images available for sharing on this page"}; var DIVI = {"item_count":"%d Item","items_count":"%d Items"}; var etSupportCenter = {"ajaxURL":"https:\/\/www.autoitscript.com\/site\/wp-admin\/admin-ajax.php","siteURL":"https:\/\/www.autoitscript.com\/site","supportCenterURL":"https:\/\/www.autoitscript.com\/site\/wp-admin\/admin.php?page=et_support_center#et_card_safe_mode","safeModeCTA":"Turn Off Divi Safe Mode","nonce":"653a94df07"}; var et_pb_custom = {"ajaxurl":"https:\/\/www.autoitscript.com\/site\/wp-admin\/admin-ajax.php","images_uri":"https:\/\/www.autoitscript.com\/site\/wp-content\/themes\/Divi\/images","builder_images_uri":"https:\/\/www.autoitscript.com\/site\/wp-content\/themes\/Divi\/includes\/builder\/images","et_frontend_nonce":"0b63a271c3","subscription_failed":"Please, check the fields below to make sure you entered the correct information.","et_ab_log_nonce":"061a4751db","fill_message":"Please, fill in the following fields:","contact_error_message":"Please, fix the following errors:","invalid":"Invalid email","captcha":"Captcha","prev":"Prev","previous":"Previous","next":"Next","wrong_captcha":"You entered the wrong number in captcha.","ignore_waypoints":"no","is_divi_theme_used":"1","widget_search_selector":".widget_search","is_ab_testing_active":"","page_id":"96","unique_test_id":"","ab_bounce_rate":"5","is_cache_plugin_active":"no","is_shortcode_tracking":"","tinymce_uri":""}; var et_pb_box_shadow_elements = []; But I need for example only (specified words or specified rows): Got it! Wiki Downloads Graphics Is that understandable? Sorry, but i'm beginner user. Edited September 1, 2019 by pecsenye
Nine Posted September 1, 2019 Posted September 1, 2019 Try this : #include <Constants.au3> #include <File.au3> #include <Array.au3> Const $sAllowed = "Got it!|Wiki|Downloads|Graphics" Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("Browser", 0, 0, 10, 10) Local $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 10, 10) GUISetState(@SW_HIDE) $oIE.navigate("https://www.autoitscript.com/site/code/") ; <-- your url here Do Sleep(100) Until Not $oIE.Busy Local $sInnerText = $oIE.document.body.innerText ConsoleWrite($sInnerText) ; MsgBox ($MB_SYSTEMMODAL,"",$sInnerText) Local $aInnerText = StringSplit (StringStripWS ($sInnerText, $STR_STRIPLEADING+$STR_STRIPTRAILING+$STR_STRIPSPACES), @CR) ;_ArrayDisplay ($aInnerText) Local $sFinal = "" For $i = 1 to $aInnerText[0] If StringRegExp ($aInnerText[$i],$sAllowed) Then $sFinal &= $aInnerText[$i] & @CR Next $aInnerText = StringSplit (StringTrimRight($sFinal,1), @CR, $STR_NOCOUNT) $aInnerText = _ArrayUnique ($aInnerText, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT) _ArrayDisplay ($aInnerText) _FileWriteFromArray ("Final.txt", $aInnerText, Default, Default, @CRLF) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now