Example - expekt bets

HTML output retrieves bets from www.expekt.com. Output is refreshing each 15 minutes from cron.

 

Output:

<table>
<tr><td colspan="4">&nbsp;</td></tr><tr><td colspan="4">Saturday 20 October 2018</td></tr>
</table>

Source code of script:

# File: expekt_main.w
# Name: EXPEKT BETS
# Description: HTML output retrieves all bets from "http://www.expekt.com/"
# Input: URL [https://en.expekt.com/odds]
# Output format: HTML file
# Output fields: Time, Subject1 - Subejct2, League(type), WinHome, Draw, WinAway

#<Logger File>
#	Global
#	FileName expekt_log.log
#	# log all messages up to debug messages
#	Level debug
#</Logger>

<Section>
	Name expekt_main

	Define $output_file expekt_output.html
    
	
	
	# clean output file
	<Action Print>
		FileName {$output_file}
		FileMode Write  
	</Action>
	
	
	
	# load content next 24hours bets
	<Action ContentURL>
		URL https://en.expekt.com/odds
		RemoveNewLine
		SetOwnCurlOpt CURLOPT_SSL_VERIFYHOST false
		SetOwnCurlOpt CURLOPT_SSL_VERIFYPEER false
		
		Cookie ASP.NET_SessionId=hnoffkfly3yqsqwmhoqxxr2m; ASP.NET_SessionId=hnoffkfly3yqsqwmhoqxxr2m; NSC_fyqflu.dpn=ffffffff098d3e4a45525d5f4f58455e445a4a423660; _gat=1; GSEK=Site=gben; mmcore.tst=0.561; mmid=1034049010%7CAgAAAApaCFz+HwwAAA%3D%3D; mmcore.pd=95903071%7CAgAAAAoBQloIXP4fDHqmI7IBADAMrg7dgdJIDwAAALpKhQXdgdJIAAAAAP//////////AAZEaXJlY3QBHwwBAAAAAAAAAAAAAP///////////////wAAAAAAAUU%3D; mmcore.srv=ldnvwcgeu01; _ga=GA1.3.1727120554.1435731658
	</Action>

	
	<Action Php>
		Code $context->setVariable('$output', $context->getVariable('$output').'<table>\n'); 
	</Action>
		
	# find all dates
	<Section While>
		Optional
		NoContext
        
		<Pattern>
			Name date
            RegExp class="cal-day section-title{:re([^"]*)}">*<span>{$date}</span>
            Trim
            Compact
        </Pattern>
        
		# prepare output
		<Action Php>
			Code $context->setVariable('$output', $context->getVariable('$output').'<tr><td colspan="4">&nbsp;</td></tr><tr><td colspan="4">'.$context->getVariable('$date').'</td></tr>\n'); 
		</Action>
		        
        # find all leagues
        <Section While>
            # continue also if date contains no bet
            Optional
			# do not create new context, push section's variables up
			NoContext
            # iterate up to beggining of next date
            EndAt class="cal-day-entry
            # the end of entries
            EndAt id="cal-loading"

            <Pattern>
                RegExp <p class="event-name{:re([^"]*)}">*<a{:re([^>]*)}>{$league}</a>
                Trim
                Compact
            </Pattern>
			
			# find all records
			<Section While>
				# continue also if league contains no bet
				Optional
				# do not create new context, push section's variables up
				NoContext
				# End at next league
				EndAt <p class="event-name
					
				<Pattern>
					RegExp <div class="cal-hour">{$time}</div>
					Compact
					Trim
				</Pattern>
				
				# iterate bets with same time
				<Section While>
					Name same-time-bets
					Optional
					NoContext
					EndAt <div class="cal-hour">

					<Section>
						# stop parsing after end of match entry
						EndAt <div class="match-entry sport

						# do not create new context, push section's variables up
						NoContext
					
						<Section Or>
							Name determine-tennis-live
							NoContext

							# tennis live
							<Section>
								Name tennis-live
								NoContext

								# tennis live entry
								<Pattern>
									RegExp <td class="team-name"><a class="team-name" href="{:re([^"]*)}">{$subject1}</a></td>
									Compact
									Trim
								</Pattern>

								# tennis live entry
								<Pattern>
									RegExp <td class="team-name"><a class="team-name" href="{:re([^"]*)}">{$subject2}</a></td>
									Compact
									Trim
								</Pattern>
							</Section>

							# normal entry
							<Pattern>
								RegExp <div class="match-name{:re([^"]*)}">*<a{:re([^>]*)}>{$subject1}{$subject2}</a>
								Compact
								Trim
							</Pattern>
						</Section>

						# split subjects if are two
						<Action Php>
							Code $s1 = $context->getVariable('$subject1');\
								$s2 = $context->getVariable('$subject2');\
								if (strlen($s2) == 0){\
									$l = explode(" - ", $s1);\
									if (count($l) == 2){\
										$context->setVariable('$subject1', $l[0]);\
										$context->setVariable('$subject2', $l[1]);\
									}\
								}
						</Action>

						# set/unset value
						<Section Or>
							Name set-unset-win-home
							NoContext
							Optional

							<Pattern>
								RegExp <span class="oddValue">{$win_home}</span>
								Compact
								Trim
							</Pattern>

							<Action Php>
								Code $context->setVariable('$win_home', "");
							</Action>
						</Section>
						
						# set/unset value
						<Section Or>
							Name set-unset-draw
							NoContext
							Optional

							<Pattern>
								RegExp <span class="oddLabel" >Dra.</span>*<span class="oddValue">{$draw}</span>
								Compact
								Trim
							</Pattern>
							
							<Action Php>
								Code $context->setVariable('$draw', "");
							</Action>
						</Section>
						
						# set/unset value
						<Section Or>
							Name set-unset-win-away
							NoContext
							Optional

							<Pattern>
								RegExp <span class="oddValue">{$win_away}</span>
								Compact
								Trim
							</Pattern>

							<Action Php>
								Code $context->setVariable('$win_away', "");
							</Action>
						</Section>
					
						# prepare output
						<Action Php>
							Code $context->setVariable('$output', $context->getVariable('$output').'<tr>\n<td>'.$context->getVariable('$time').'</td>\n<td>'.\
								$context->getVariable('$subject1').' - '.$context->getVariable('$subject2').'</td>\n<td>'.$context->getVariable('$league').\
								'</td>\n<td>'.$context->getVariable('$win_home').' '.$context->getVariable('$draw').' '.$context->getVariable('$win_away').'</td>\n</tr>'); 
						</Action>
					</Section>
				</Section>
			</Section>
        </Section>
    </Section>
    
	# prepare output
	<Action Php>
		Code $context->setVariable('$output', $context->getVariable('$output').'</table>\n'); 
	</Action>
	
	# store output in file
    <Action Print>
        FileName {$output_file}
        Text {$output}
    </Action>

</Section>

Main expekt_main