Что нового

Парсинг выпадающего списка из html

Kreol2013

Новичок
Сообщения
9
Репутация
0
Есть у меня 10 сайтов с которых надо спарсить цены.
Пишу так
Код:
#include <IE.au3>
#Include <INet.au3> ;Подключаем библиотеку
$sLogin = 'domnnn.com'
$sUrl = 'https://secure.fatcow.com/register/registration.bml?masters=445&promos=dir_intr18_24&flowid=12&cid=951'

$oIE = _IECreate($sUrl)
$oLogin = _IEGetObjById($oIE, 'dom_lookup')
$oButton = _IEGetObjById($oIE, 'button')

_IEFormElementSetValue($oLogin, $sLogin)
_IEAction($oButton, 'click')
_IELoadWait($oIE)
sleep(4000)
; дальше пытался раскрутить код из этого примера http://autoit-script.ru/index.php/topic,10471.0.html, но...
$oElements = _IETagNameGetCollection($oIE, 'feature-row')
For $oElement In $oElements
    If $oElement.value == '73291' Then
        ;ConsoleWrite(_IEPropertyGet($oElement, 'innertext'))
        ExitLoop
    EndIf
Next
MsgBox(0,"",$oElement.value)


html страница имеет такой вид.
Код:
<div class="displaybox reg-box registration-purchase-information registration-box">
   <h2>Purchase Information</h2>
<input type="hidden" id="hostingprice" value="88.00">
<input type="hidden" id="hostingofferid" value="73291">
<table width="660">

   <tr class="feature-row">
      <td align="right"><label for="changefrequency_3">The FatCow Plan:</label></td>
      <td align="left" id="freqDrop">
      <select name="changefrequency_3" id="changefrequency_3" class="norm" onchange="updatesetup(this)"><option value="73290">$4.67 per month (billed $56.04 for 12 months)</option>
<option value="73291" selected>$3.67 per month (billed $88.00 for 24 months)</option>
<option value="73292">$3.67 per month (billed $132.00 for 36 months)</option></select> </td>
   </tr>
   <tr class="feature-row">
      <td align="right">
         <label>Instant Activation:</label>
      </td>
      <td align="left">
         INCLUDED FREE!
      </td>
   </tr>
Код:
class="feature-row"
здесь 6 штук. Наш 1-й.
Нужно из всего этого получить строку которая будет <option value="ххххх" selected>

Код:
<option value="73291" selected>$3.67 per month (billed $88.00 for 24 months)</option>
а в результате затолкать в файл цифру 3.67
Буду очень признателен за быстрый ответ
 

sngr

AutoIT Гуру
Сообщения
1,010
Репутация
408
Код:
#include 'array.au3'
$file=FileRead(@ScriptDir&'\123')
$str=StringRegExp($file,'(?si)<option value="\S+" selected>\$(\S+) per month',3)
_ArrayDisplay($str)
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
Kreol2013,
Попробуйте так.
Код:
#include <IE.au3>
;без проверок на ошибки
RunWait(@SystemDir & '\RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2', '', @SW_HIDE) ;del cookie
$iCount = 0
$sLogin = 'domnnn.com'
$sUrl = 'https://secure.fatcow.com/register/registration.bml?masters=445&promos=dir_intr18_24&flowid=12&cid=951'
$sUrlWait = 'https://secure.fatcow.com/register/registration.bml'
$oIE = _IECreate($sUrl)
$oLogin = _IEGetObjById($oIE, 'dom_lookup')
$oButton = _IEGetObjById($oIE, 'button')

_IEFormElementSetValue($oLogin, $sLogin)
_IEAction($oButton, 'click')
$iStart = TimerInit()
While TimerDiff($iStart) < 10000
	Sleep(1000)
	If _IEPropertyGet($oIE, 'locationurl') == $sUrlWait Then ExitLoop
WEnd
_IELoadWait($oIE)
$oSelect = _IEGetObjById($oIE, 'changefrequency_1')
ConsoleWrite($oSelect.innertext & @LF)
ConsoleWrite('====' & @LF)
$oOpts = _IETagNameGetCollection($oSelect, 'option')
For $oOpt In $oOpts
	$sIT = $oOpt.innertext
	$sSearch = StringMid($sIT, 2, StringInStr($sIT, 'per') - 3)
	ConsoleWrite($iCount & @TAB & $sIT & @TAB & $sSearch & @LF)
	;$oOpt.selected = True
	$iCount += 1
	;Sleep(1000)
Next
 
Автор
K

Kreol2013

Новичок
Сообщения
9
Репутация
0
Код:
$oSelect = _IEGetObjById($oIE, 'changefrequency_1')

changefrequency_1 меняется при заходах на страничку на changefrequency_2 и тд.
А... где оно должно показать результат? Что-то не совсем я понял
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
Kreol2013 [?]
А... где оно должно показать результат? Что-то не совсем я понял
Замените
Код:
;...
ConsoleWrite($iCount & @TAB & $sIT & @TAB & $sSearch & @LF)
;на
MsgBox(64, 'Info', $iCount & @TAB & $sIT & @TAB & $sSearch)
;...
 
Верх