@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
UIWebView *web =
[[UIWebView alloc] initWithFrame:
[UIScreen mainscreen].bounds];
UIButton *back =
[[UIButton alloc] Initwithframe:cgrectmake
(0, 0, self.view.frame.size.width,self.view.frame.size.width/7.5)];
[Back SetBackgroundColor: [Uicolor Orangecolor];
[Back settitle:@ ' back ' forstate:uicontrolstatenormal];
[Back Addtarget:self
Action: @selector (back)
Forcontrolevents:uicontroleventtouchupinside];
Take Bing as an example
[Web loadrequest:
[Nsurlrequest Requestwithurl:
[Nsurl URLWithString:
@ "Http://www.bing.com/?FORM=Z9FD1"]];
Web.delegate = self;
Web.scalespagetofit =yes;
Web.scrollView.delegate = self;
Self.web = web;
[Self.view Addsubview:web];
[Self.view Addsubview:back];
}
#pragma Mark---Delegate
-(void) Webviewdidstartload:
(UIWebView *) webview{
NSLog (@ "Start loading--");
}
-(void) Webviewdidfinishload:
(UIWebView *) WebView {
NSLog (@ "Load complete---");
Gets the title of the current page
NSString *title =
[WebView
Stringbyevaluatingjavascriptfromstring:
@ "Document.title"];
NSLog (@ "title====%@", title);
Get current URL
NSString *url =
[WebView
Stringbyevaluatingjavascriptfromstring:
@ "Document.location.href"];
NSLog (@ "url===%@", URL);
Get the page code
NSString *html =
[WebView
Stringbyevaluatingjavascriptfromstring:
@ "Document.documentElement.innerHTML"];
NSLog (@ "html====%@", HTML);
Stitching strings to find the control price and assign a value based on the page name
NSString *str = @ "With _ Simple book";
NSString *jsstr =
[NSString stringWithFormat:
@ "Document.getelementsbyname (' Q ') [0].value = ('%@ ');", str];
[WebView STRINGBYEVALUATINGJAVASCRIPTFROMSTRING:JSSTR];
}
-(void) WebView:
(UIWebView *) WebView
Didfailloadwitherror: (Nserror *) Error {
NSLog (@ "Load failed ===%@", error);
}
When the page location is top not allowed to continue dropdown
-(void) Scrollviewdidscroll:
(Uiscrollview *) ScrollView {
if (SELF.WEB.FRAME.ORIGIN.Y = = 0) {
Self.web.scrollView.bounces = NO;
Return
}
}
WebView every page jump will be executed, here to get the data you want
-(BOOL) WebView:
(UIWebView *) WebView
Shouldstartloadwithrequest: (nsurlrequest *) request
Navigationtype: (uiwebviewnavigationtype) Navigationtype {
NSLog (@ "page jump");
return YES;
}
Return
-(void) Back {
[Self.web GoBack];
}