Search:
<% SearchTerm = Request.QueryString( "search_term" ) ' If the user entered a search term we'll scrape. If SearchTerm<>"" Then ' Instantiate a remote scraping session (also known ' as screen-scraper's ASP driver). Set objRemoteSession = Server.CreateObject( "Screenscraper.RemoteScrapingSession" ) ' Initialize the session. If you're running screen-scraper ' on a different computer than the one the ASP file resides ' on you'll want to modify and use the top version instead ' of the bottom one. Call objRemoteSession.Initialize( "Shopping Site", "192.168.0.4", 8778 ) 'Call objRemoteSession.Initialize( "Shopping Site" ) ' Set the variables. ' Remember that these two top variables correspond to the POST ' parameters we use for the "Login" scrapeable file. Call objRemoteSession.SetVariable( "EMAIL_ADDRESS", "test@test.com" ) Call objRemoteSession.SetVariable( "PASSWORD", "testing" ) ' This parameter is the search term the user designated. Call objRemoteSession.SetVariable( "SEARCH", SearchTerm ) ' We start screen-scraper at page 1 of the search results. ' Note that we could have also done this in an "initialize" ' script within screen-scraper, which is common. Call objRemoteSession.SetVariable( "PAGE", "1" ) ' Check for errors. If objRemoteSession.isError Then Response.Write( "Error: " & objRemoteSession.GetErrorMessage ) Else ' Tell the session to scrape. This method call might take ' a little while since it will need to wait for screen-scraper ' to fully extract the data before it returns. Call objRemoteSession.Scrape ' We check to see if we got any records back by looking for ' a title in the first data record in the set. If IsNull( objRemoteSession.GetVariable( "PRODUCTS" ) ) Then ' Output a message if we didn't find any results. %>
Sorry, no results were found for <%= SearchTerm %>.
<% Else ' Output the table headers. %> <% ' Get the data set that was stored by screen-scraper in a ' session variable. This data set corresponds to the "PRODUCTS" ' extractor pattern found under the "Details page" scrapeable ' file. Call objRemoteSession.StoreVariable( "PRODUCTS" ) ' Iterate through each of the data records screen-scraper ' extracted, outputting each of them to the browser. For i = 0 to objRemoteSession.GetNumDataRecordsForDataSet( "PRODUCTS" ) - 1 %> <% Next %>
Title Price Model Shipping Weight Manufactured By
<%= objRemoteSession.GetDataSetValue( "PRODUCTS", i, "TITLE" ) %> <%= objRemoteSession.GetDataSetValue( "PRODUCTS", i, "PRICE" ) %> <%= objRemoteSession.GetDataSetValue( "PRODUCTS", i, "MODEL" ) %> <%= objRemoteSession.GetDataSetValue( "PRODUCTS", i, "SHIPPING_WEIGHT" ) %> <%= objRemoteSession.GetDataSetValue( "PRODUCTS", i, "MANUFACTURED_BY" ) %>
<% End If End If ' Disconnect from the server. Call objRemoteSession.Disconnect End If %>