Jump to content

regexp questions


Recommended Posts

hi guys  i  want  extract  , at amazon search page  , a  name of product searched ,price  and foto , and  put result in listview

i try to do a simple script in this mode

 

Local $urlAmaS = "https://www.amazon.it/s/ref=nb_sb_noss?__mk_it_IT=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Daps&field-keywords="

_Amazon_Search("i7", $urlAmaS)


Func _Amazon_Search($frases, $url, $Hide = 0, $slow = 0)

    If $Hide = 0 Then
        $Hide = 1
    EndIf
    If $slow = 0 Then
        $slow = 1000
    EndIf

    Global $oIE = _IECreate($url&$frases, 0, $Hide, 1, 1) ; <--- 0011 invisible explorer  <--- 0111 visible explorer
    _IELoadWait($oIE)
Sleep($slow)
    Local $sText = _IEBodyReadText($oIE)
    Local $iFindBadPage = StringInStr($sText, "This page can’t be displayed")

    If $iFindBadPage <> 0 Then
        If ProcessExists("iexplore.exe") Then ; Check if the internet esplorer process is running.
            ProcessClose("iexplore.exe")
        EndIf
        Sleep($slow)
        $oIE = _IECreate($url&$frases, 0, $Hide, 1, 1) ; <--- 0011 invisible explorer  <--- 0111 visible explorer
        _IELoadWait($oIE)
    EndIf

        Local $sLHtml = _IEBodyReadHTML($oIE)
        Local $aL = StringRegExp($sLHtml, 'href="(.*?)"><img src="(.*?)" srcset="(.+?)title="(.*?)" href="', 3)
        _ArrayDisplay($aL)

EndFunc   ;==>_Amazon_Search

but the regrexp not work correct  , anyone  can help me ???

thankz so much  at all

 

 

 

Link to comment
Share on other sites

When possible and with the usual precautions, this approach (much faster) looks better

#Include <Array.au3>

$sTarget = "https://www.amazon.it/s/ref=nb_sb_noss?__mk_it_IT=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Daps&field-keywords=" & "i7"
$oHTTP = ObjCreate("Microsoft.XMLHTTP")
$oHTTP.Open("GET", $sTarget, False)
$oHTTP.Send()
$s = BinaryToString($oHTTP.ResponseText)
$oHTTP = 0
;filewrite("1.txt", $s)

Local $aL = StringRegExp($s, '(?s)href="([^"]+)"><img src="([^"]+)"\h*srcset="[^"]+.*?title="([^"]+)" href="', 3)
_ArrayDisplay($aL)

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...