T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 22 Screen Scraping Application Introducing String Processing.

Slides:



Advertisements
Similar presentations
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Getting Started with Java.
Advertisements

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
The Web Warrior Guide to Web Design Technologies
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Web Application Introducing Visual Web Developer 2008 Express and the.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Flag Quiz Application Introducing One-Dimensional Arrays and ComboBox es.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Shipping Hub Application Introducing Generic Collections, LINQ, For Each...Next.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Introducing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Fund Raiser Application Introducing Scope, Pass-by-Reference and Option Strict.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 27 - Phone Book Application Introducing Multimedia.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Ticket Information Application Introducing Sequential-Access Files.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 5 Completing the Inventory Application Introducing Programming.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Security Panel Application Introducing the Select Case Multiple-Selection Statement.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 23.1 Test-Driving the Screen Scraping Application.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Microwave Oven Application Building Your Own Classes and Objects.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 4 Introduction to Classes, Objects, Methods and strings
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 2.1 Test-Driving the Welcome Application 2.2.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 15 – Fund Raiser Application Introducing.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Web Application: Client Tier Introducing Web Controls.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Invitation to Computer Science 6 th Edition Chapter 10 The Tower of Babel.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
Microsoft Visual Basic 2008: Reloaded Third Edition
Chapter 6 JavaScript: Introduction to Scripting
Strings, StringBuilder, and Character
Primitive Types Vs. Reference Types, Strings, Enumerations
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
CIS16 Application Development and Programming using Visual Basic.net
JavaScript: Objects.
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Unit-2 Objects and Classes
Presentation transcript:

T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Screen Scraping Application Introducing String Processing

 2009 Pearson Education, Inc. All rights reserved. 2 Outline 22.1 Test-Driving the Screen Scraping Application 22.2 Fundamentals of String s 22.3 Analyzing the Screen Scraping Application 22.4 Locating Substrings in String s 22.5 Extracting Substrings from String s 22.6 Replacing Substrings in String s 22.7 Other String Methods

 2009 Pearson Education, Inc. All rights reserved. 3 In this tutorial you will learn: ■Manipulate String objects. ■Use properties and methods of class String. ■Search for substrings within String s. ■Extract substrings within String s. ■Replace substrings within String s. Objectives

 2009 Pearson Education, Inc. All rights reserved. 4 ■HTML (HyperText Markup Language) is a technology for describing web pages. ■Extracting desired information from HTML is called screen scraping. Introduction

Application Requirements  2009 Pearson Education, Inc. All rights reserved Test-Driving the Screen Scraping Application An online European auction house wants to expand its business to include bidders from the United States. However, all of the auction house’s web pages currently display their prices in euros, not dollars. The auction house wants to generate separate web pages for American bidders that display the prices of auction items in dollars. These new web pages will be generated by using screen-scraping techniques on the already existing web pages.

Application Requirements  2009 Pearson Education, Inc. All rights reserved Test-Driving the Screen Scraping Application (Cont.) You have been asked to build a prototype application that tests the screen-scraping functionality. The application must search a sample string of HTML and extract information about the price of a specified auction item. For testing purposes, a ComboBox should be provided that contains auction items listed in the HTML. The selected item’s amount must then be converted to dollars. Assume the exchange rate is one euro to 1.58 dollars (that is, one euro is equivalent to $1.58).

 2009 Pearson Education, Inc. All rights reserved. 7 Test-Driving the Screen Scraping Application ■Run the completed application (Fig. 22.1). Figure 22.1 | Screen Scraping application’s Form. Label containing HTML

 2009 Pearson Education, Inc. All rights reserved. 8 Test-Driving the Screen Scraping Application (Cont.) ■Select an item name from the ComboBox, as shown in Figure Figure 22.2 | Selecting an item name from the ComboBox. ComboBox’s drop-down list

 2009 Pearson Education, Inc. All rights reserved. 9 Test-Driving the Screen Scraping Application (Cont.) ■Click the Search Button to display the price for the selected item (Fig. 22.3). Figure 22.3 | Searching for the item’s price. Extracted price (converted to dollars) Price located in HTML string (specified in Euros)

 2009 Pearson Education, Inc. All rights reserved. 10 ■A string is a series of characters treated as a single unit. "This is a string!" ■These characters can be uppercase letters, lowercase letters, digits and various special characters, such as +, -, *, /, $ and others. ■ String property Length returns the length of the String Fundamentals of String s

 2009 Pearson Education, Inc. All rights reserved. 11 ■ String property Chars returns the character located at a specific index in a String : string1.Chars(0) ■Any String method or operator that appears to modify a String actually returns a new String that contains the results. ■ String s are immutable objects—that is, characters in String s cannot be changed after the String s are created Fundamentals of String s (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 12 ■Figure 22.4 lists several String methods. Figure 22.4 | String methods introduced in earlier tutorials Fundamentals of String s (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 13 When the Form loads: Display the HTML that contains the items’ prices in a Label When the user clicks the Search Button: Search the HTML for the item the user selected from the ComboBox Extract the item’s price Convert the item’s price from euros to dollars Display the item’s price in a Label 22.3 Analyzing the Screen Scraping Application

 2009 Pearson Education, Inc. All rights reserved. 14 ■Use an ACE table to convert pseudocode into Visual Basic (Fig. 22.5). Figure 22.5 | ACE table for Screen Scraping application. Action/Control/Event (ACE) Table for the Screen Scraping Application

 2009 Pearson Education, Inc. All rights reserved. 15 Locating the Selected Item’s Price ■Double click the Search Button on the template application’s Form to generate an event handler (Fig. 22.6). Figure 22.6 | searchButton_Click event handler.

 2009 Pearson Education, Inc. All rights reserved. 16 Locating the Selected Item’s Price (Cont.) ■Add lines 17–21 of Figure 22.7 to the searchButton_Click event handler. Figure 22.7 | searchButton_Click event-handler declarations.

 2009 Pearson Education, Inc. All rights reserved. 17 ■ String method IndexOf (Fig. 22.8) locates the first occurrence of the specified item in the HTML string. –If IndexOf finds the specified item name, the index at which the substring begins in the String is returned. –If IndexOf does not find the substring, it returns –1. Locating the Selected Item’s Price (Cont.) Figure 22.8 | Locating the desired item name. Search for the SelectedItem in the String html

 2009 Pearson Education, Inc. All rights reserved. 18 ■This version of method IndexOf (Fig. 22.9) takes two arguments—the substring to find and the index in the String to begin searching. ■In this case, the substring to find (indicating the beginning of the price) is "€“. Figure 22.9 | Locating the desired item price. Locate the beginning of the price in html Locating the Selected Item’s Price (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 19 ■A tag directly follows every price in the HTML string, so the index of the first tag after priceBegin marks the end of the current price (Fig ). Figure | Locating the end of the item’s price. Locate the end of the price in html Locating the Selected Item’s Price (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 20 ■The LastIndexOf locates the last occurrence of a substring in a String. ■If method LastIndexOf finds the substring, it returns the starting index of the specified substring in the String ; otherwise, LastIndexOf returns –1. ■Figure shows examples of the three versions Locating Substrings in String s Figure | LastIndexOf examples.

 2009 Pearson Education, Inc. All rights reserved. 21 ■The first argument ( priceBegin ) specifies the starting index. ■The second argument ( priceEnd - priceBegin ) specifies the length of the substring to be copied (Fig ). Figure | Retrieving the desired price. Extract price from html Retrieving the Desired Item’s Price

 2009 Pearson Education, Inc. All rights reserved. 22 ■ String method Replace (Fig ) is used to return a new String object in which every occurrence of substring "€" is replaced with the empty String. ■ String method Format displays the price in resultLabel as currency. Converting the Price to Dollars Figure | Converting the price to dollars. Replace "€" with "" and convert the amount to dollars

 2009 Pearson Education, Inc. All rights reserved. 23 ■Double click the Form to generate an empty Load event handler (Fig ). Figure | Load event for the Form. Displaying the HTML String

 2009 Pearson Education, Inc. All rights reserved. 24 ■ String method Replace (Fig ) replaces every occurrence of "€" with "&€". –For the text to display in a Label correctly, you must prefix it with an additional ampersand. Figure | Displaying the HTML string in a Label. Replace all occurrences of "&euro" with "&&euro" Displaying the HTML String (Cont.)

 2009 Pearson Education, Inc. All rights reserved Other String Methods ■Figure lists some of the methods for manipulating String s. Figure | Description of some other String methods. (Part 1 of 2.)

 2009 Pearson Education, Inc. All rights reserved Other String Methods (Cont.) Figure | Description of some other String methods. (Part 2 of 2.)

 2009 Pearson Education, Inc. All rights reserved. 27 ■Figure presents the source code for the Screen Scraping application. Outline (1 of 4 )

 2009 Pearson Education, Inc. All rights reserved. 28 Outline (2 of 4 ) Search for the SelectedItem in the String html

 2009 Pearson Education, Inc. All rights reserved. 29 Outline (3 of 4 ) Locate the beginning of the price in html Locate the end of the price in html Extract the price from html Replace "€" with the empty String

 2009 Pearson Education, Inc. All rights reserved. 30 Outline (4 of 4 ) Replace "€" with "&&euro"