Jump to content
quimao

Some guy plz help me

Recommended Posts

quimao

first one, i'm sorry for my bad english. Actually, it's very bad
I had a problem when i tried to get the HTML code of the Element object in a webpage. When i run my code, it'd not come off as i hoped
This is my code

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <IE.au3>
#include <FileConstants.au3>

Global $_browser

$_browser =_IECreate("about:blank")

For $i =1 to 20249
    Local $link, $_getIDbrowser, $_getIDelement
    $link="http://tratu.coviet.vn/hoc-tieng-anh/cap-cau-song-ngu/vietgle-tra-tu/tat-ca/trang-"&$i&".html"
    _IENavigate($_browser,$link)
    $_getIDbrowser = _IEGetObjById($_browser , "ctl00_ContentPlaceHolderMain_ctl00")
    $_getIDelement = _IEPropertyGet($_getIDbrowser,"innerhtml")
        writefile($_getIDelement)
    $_getIDelement=""
    Sleep(100)
Next


func writefile($line)
    $file= FileOpen("C:\exports.html",129)
    FileWriteLine($file,$line)
    FileClose($file)
EndFunc

 

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

Can you please tell us what kind of information you try to grab from 20249 web pages?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
quimao

Welcome to AutoIt and the forum!

Can you please tell us what kind of information you try to grab from 20249 web pages?

Oh, sorry i forgot to say it. I want to save the english sentences to serve for my learning english. But I feel it difficult to obtain data in text format. So I decided to take it in the form of HTMT. In that pageIt is the data in the path from  "... .trang-1.html" to "... .trang-20429.html".When I run my script, it only runs until "..... trang-2.html" then stop. The output file do not have to add any more data. That's my problem. I tried to change the variable $i=3 but i got one more time. It's still not succeed

Edited by quimao

Share this post


Link to post
Share on other sites
JohnOne

Your English is fine, but you're not getting your point across.

Best guess...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <IE.au3>
#include <FileConstants.au3>

Global $_browser

$_browser =_IECreate("about:blank")

$file= FileOpen("C:\exports.html",129)

For $i =1 to 20249
    Local $link, $_getIDbrowser, $_getIDelement
    $link="http://tratu.coviet.vn/hoc-tieng-anh/cap-cau-song-ngu/vietgle-tra-tu/tat-ca/trang-"&$i&".html"
    _IENavigate($_browser,$link)
    $_getIDbrowser = _IEGetObjById($_browser , "ctl00_ContentPlaceHolderMain_ctl00")
    $_getIDelement = _IEPropertyGet($_getIDbrowser,"innerhtml")
        writefile($_getIDelement)
    $_getIDelement=""
    Sleep(100)
Next

FileClose($file)

func writefile($line)
    
    FileWriteLine($file,$line)
    
EndFunc

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
water

What your code is missing is error testing. Check after each function call if it was successful or if the function returned an error.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
mikell

To get data in text format you could try this

#include <IE.au3>
#include <FileConstants.au3>

$_browser =_IECreate("about:blank")
$file= FileOpen("exports.txt",129)

For $i =1 to 5
    Local $link, $_getIDbrowser, $_getIDelement
    $link="http://tratu.coviet.vn/hoc-tieng-anh/cap-cau-song-ngu/vietgle-tra-tu/tat-ca/trang-"&$i&".html"
    _IENavigate($_browser,$link)
    $_getIDbrowser = _IEGetObjById($_browser , "ctl00_ContentPlaceHolderMain_ctl00")
    $_getIDelement = StringRegExpReplace(_IEPropertyGet($_getIDbrowser,"innertext"), '\v{2,}', @crlf)
        writefile("___ page " & $i &@crlf&@crlf)
        writefile($_getIDelement)
    Sleep(100)
Next

FileClose($file)

func writefile($line)
    FileWriteLine($file,$line)
EndFunc

 

Share this post


Link to post
Share on other sites
quimao

@mikell:
Thank you so much, can't believe I could forget this  "innerText" but your script runs just like mine. The Output file only the data record of the first two paths "... trang-1.html" & "........ .trang-2.html" and no added more. Did your script work in all?

@Johnone:
the truth is I only know English expressions like that. I also want to explain more but my knowledge of English is limited. sorry you

@water:
Oh I know, my script runs in the first two paths, and output file write data of that two paths, but from the path of three. It doesn't run anymore

 

Edited by quimao

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×