1. 程式人生 > >在OC修改/獲取網頁內容的方法

在OC修改/獲取網頁內容的方法

OC提供了Api,呼叫網頁中的JS方法:stringByEvaluatingJavaScriptFromString;

通過這個方法,可以獲取網頁的URL,Tilte,插入JS指令碼。

測試程式碼:

  1. -(void)webViewDidFinishLoad:(UIWebView *)webView  
  2. {  
  3.     //獲取URL
  4.     NSString *curURL = [webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];  
  5.     //獲取標題
  6.     /* 
  7.      關於網頁的標題
     
  8.      在網頁HTML程式碼中,網頁標題位於<head> </head>標籤之間。其形式為: 
  9.        <title>網路營銷教學網站</title> 
  10.      */
  11.     NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];  
  12.     //修改屬性值
  13.     NSString *js_result = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('good')[0].color='red';"
    ];  
  14.     //呼叫JS方法
  15.     [webView stringByEvaluatingJavaScriptFromString:@"funnight()"];  
  16.     //結果列印
  17.     NSLog(@"jsresult=%@",js_result);  
  18.     NSLog(@"title=%@",title);  
  19.     NSLog(@"curURL=%@",curURL);  
  20. }  

相關推薦

OC修改/獲取網頁內容方法

OC提供了Api,呼叫網頁中的JS方法:stringByEvaluatingJavaScriptFromString; 通過這個方法,可以獲取網頁的URL,Tilte,插入JS指令碼。 測試程式碼: -(void)webViewDidFinishLoad:(U

php獲取網頁內容方法

<?php $url = "http://www.jb51.net"; $contents = file_get_contents($url); //如果出現中文亂碼使用下面程式碼 //$getcontent = iconv("gb2312", "utf-8",$contents); echo

php獲取網頁內容的三種方法

3種利用php獲得網頁原始碼抓取網頁內容的方法,我們可以根據實際需要選用。 1、使用file_get_contents獲得網頁原始碼 這個方法最常用,只需要兩行程式碼即可,非常簡單方便。 參考程式碼: <?php $fh= file_get_contents('http

PHP 獲取網頁內容的三種方法

抓取到的內容在通過正則表示式做一下過濾就得到了你想要的內容。 file_get_contents() 把整個檔案讀入一個字串中。 Java程式碼  <meta charset="utf-8">     <?php    $url = "http

PHP獲取網頁內容的幾種方法

方法1: 用file_get_contents 以get方式獲取內容 <?php $url='http://www.domain.com/?para=123'; $html = file_get_contents($url); echo $html; ?> 方法2:用file

HttpURLConnection獲取網頁內容,解決亂碼的通用方法

      由於網頁內容的字符集編碼不一定都採用UTF-8編碼,所以通過HttpURLConnection獲取的網頁內容經常會出現亂碼的問題。 網頁內容的編碼可能是UTF-8,也可能是GBK、GB23

vc++使用IWinHttpRequest獲取網頁內容亂碼

[0 網頁 unicode code com box get ant 解決方法 mfc項目的字符集為unicode字符集 亂碼前代碼: CString rspStr = pHttpReq->ResponseText; MessageBox(rspStr); 亂碼效

C# HttpClient Get獲取網頁內容

獲取網頁 lec net IV 內容 pen style 網頁 pac 1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq;

nodejs 使用 body-parser 獲取網頁內容

parse nodejs 網頁 url end func body parser .post var bodyParser = require(‘body-parser‘); var urlencodedParser = bodyParser.urlencoded({

關於java獲取網頁內容

最近專案需求,做一些新聞站點的爬取工作。1.簡單的jsoup爬取,靜態頁面形式; String url="a.atimo.cn";//靜態頁面連結地址Document doc = Jsoup.connect(url).userAgent("Mozilla").timeout(4000).get();

php通過登入後的cookie以及使用者代理然後通過curl獲取網頁內容

function curl_get_https($url, $data=array(), $header=array(), $timeout=30){     $ch = curl_init();     curl_setopt($ch, CURLOPT_

Python爬蟲:lxml模組分析並獲取網頁內容

運用css選擇器: # -*- coding: utf-8 -*- from lxml import html page_html = ''' <html><body> <input id="input_id" value="input value" nam

C#獲取網頁內容的三種方式

本文轉載自http://www.cnblogs.com/ceachy/articles/CSharp_Retrive_Page_Document.html,Luke Zhang的部落格。 搜尋網路,發現C#通常有三種方法獲取網頁內容,使用WebClient、WebB

如何使用curl獲取網頁內容

HttpRequest.class.php <?php /*  * 使用curl擴充套件發出http的get或post請求  */ class HttpRequest {     //url,請求的伺服器地址     private $url = '';     

獲取網頁內容,呼叫語音控制元件

安裝pip,這是一個包含很多python外掛的庫 wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate sudo pyt

獲取網頁內容WebClient

/// <summary> /// 獲取網頁內容 /// </summary> /// <param name="url">網址</param> private stati

Python獲取網頁內容、使用BeautifulSoup庫分析html

利用 urllib包 獲取網頁內容 #引入包 from urllib.request import urlopen response = urlopen("http://fund.eastmoney.com/fund.html") html = resp

使用selenium和phantomJS瀏覽器獲取網頁內容的小演示

# 使用selenium和phantomJS瀏覽器獲取網頁內容的小演示 # 匯入包 from selenium import webdriver # 使用selenium庫裡的webdriver方法呼叫PhantomJS瀏覽器例項一個瀏覽器的操作物件 # 括號裡的引數為PhantomJS瀏覽器在電

使用php獲取網頁內容

1。使用xmlhttp物件,類似於asp中的ActiveXObject物件,其實xmlhttp無非就是get和put的操作,在php裡面 get的,直接用file_get_contents/fopen/readfile這些函式就是了 put的,自己寫fsockopen傳送也行

python3 使用requests獲取網頁內容

在命令列裡輸入命令安裝模組 pip install requests pip install random 以獲取豆瓣網頁內容為例 #匯入需要用到的模組 import requests #準備一個網址 url='https://movie.douban.c