当前位置:首页 » 安卓系统 » android获取网页源码

android获取网页源码

发布时间: 2022-06-26 04:14:10

A. android webview加载某个网页,之后通过这个网页调到了另一个页面,怎么获取这个页面的网址和源码

mWebView.setWebViewClient(new WebViewClient(){
// 这个方法在用户试图点开页面上的某个链接时被调用
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url!=null) {
// 如果想继续加载目标页面则调用下面的语句
// view.loadUrl(url);
// 如果不想那url就是目标网址,如果想获取目标网页的内容那你可以用HTTP的API把网页扒下来。
}
// 返回true表示停留在本WebView(不跳转到系统的浏览器)
return true;
}
});

B. android怎么获取JS执行之后的网页源代码

可以试用phantomjs加载网页,执行js,然后获取执行后的网页代码。
官网: http://phantomjs.org/

C. android怎么获取网页数据

下面介绍三种获取网页数据的代码
例子来自于android学习手册,android学习手册包含9个章节,108个例子,源码文档随便看,例子都是可交互,可运行,源码采用android studio目录结构,高亮显示代码,文档都采用文档结构图显示,可以快速定位。360手机助手中下载,图标上有贝壳
//第一种
/**获取参数(ArrayList<NameValuePair> nameValuePairs,String url)后post给远程服务器
* 将获得的返回结果(String)返回给调用者
* 本函数适用于查询数量较少的时候
*/
public String posturl(ArrayList<NameValuePair> nameValuePairs,String url){
String result = "";
String tmp= "";
InputStream is = null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
return "Fail to establish http connection!";
}

try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();

tmp=sb.toString();
}catch(Exception e){
return "Fail to convert net stream!";
}

try{
JSONArray jArray = new JSONArray(tmp);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Iterator<?> keys=json_data.keys();
while(keys.hasNext()){
result += json_data.getString(keys.next().toString());
}
}
}catch(JSONException e){
return "The URL you post is wrong!";
}

return result;
}

//第二种
/**获取参数指定的网页代码,将其返回给调用者,由调用者对其解析
* 返回String
*/
public String posturl(String url){
InputStream is = null;
String result = "";

try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
return "Fail to establish http connection!"+e.toString();
}

try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();

result=sb.toString();
}catch(Exception e){
return "Fail to convert net stream!";
}

return result;
}

//第三种
/**获取指定地址的网页数据
* 返回数据流
*/
public InputStream streampost(String remote_addr){
URL infoUrl = null;
InputStream inStream = null;
try {
infoUrl = new URL(remote_addr);
URLConnection connection = infoUrl.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection)connection;
int responseCode = httpConnection.getResponseCode();
if(responseCode == HttpURLConnection.HTTP_OK){
inStream = httpConnection.getInputStream();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return inStream;

D. 游戏软件怎么查看源代码

源代码是看不成的,因为游戏软件打包好做成app的话,是没法看源码的,虽然存在一些特殊情况下,我们可以推测出exe程序是用什么程序写的。但是多数情况下,我们是无法只根据一个exe程序就判断出来的。

根据exe程序我们是无法直接得到程序的源码的。虽然也有一些用于逆向工程的办法,但那不可能把已经是exe的程序反回到它原始的源码情况。而且这些工具都很难用。你可以用“反编译”搜到很多工具,但是说实话,即便是这方面的专家,要看懂反编译以后的程序也不是一件轻松的事情。

E. android studio 怎么抓去网页媒体资源

首先,也是很重要的一步,就是下载jar包,丢到libs里面
Android studio玩家可以不下载jar包,在Gradle里面加入
dependencies {undefined
compile 'org.jsoup:jsoup:1.9.2'
}复制代码
然后,找到你心仪的网页去抓取数据
这里我们我继续使用美食的网页,然后右键查看网页源码,或者按F12,接下来可以看到一大堆标签:
Paste_Image.png
找到需要的,例如上图这个 “美食天下” ,可以看到 “美食天下” 是放在以
为节点的 中,要获取这个“美食天下”,代码可以这样写:
try {undefined
//从一个URL加载一个Document对象。
Document doc = Jsoup.connect("http://home.meishichina.com/show-top-type-recipe.html").get();
//选择“美食天下”所在节点
Elements elements = doc.select("div.top-bar");
//打印 a标签里面的title
Log.i("mytag",elements.select("a").attr("title"));
}catch(Exception e) {undefined
Log.i("mytag", e.toString());
}复制代码
接下来看一下打印出来的结果:
Paste_Image.png
Jsoup.connect(String url)方法从一个URL加载一个Document对象。如果从该URL获取HTML时发生错误,便会抛出 IOException,应适当处理。
一旦拥有了一个Document,你就可以使用Document中适当的方法或它父类 Element和Node中的方法来取得相关数据。
public class Element extends Node
public class Document extends Element复制代码
很多文章都是说一大堆原理然后放出一个简单的例子,就跟我上面简单的打了一个log一样,然后发现用起来的时候是没那么简单的。为了大家能不看文档也可以直接使用(并且看不懂那一大堆标签也可以用),我决定再举一个例子(其实也就是比上面多打几个log):
下图红色框框是我们要获取的数据,可以看到他们对应的节点就是蓝色圆圈里面的
Paste_Image.png
废话不多说上代码
try {undefined
//还是一样先从一个URL加载一个Document对象。
Document doc = Jsoup.connect("http://home.meishichina.com/show-top-type-recipe.html").get();
//“椒麻鸡”和它对应的图片都在复制代码

Elements titleAndPic = doc.select("div.pic");
//使用Element.select(String selector)查找元素,使用Node.attr(String key)方法取得一个属性的值
Log.i("mytag", "title:" + titleAndPic.get(1).select("a").attr("title") + "pic:" + titleAndPic.get(1).select("a").select("img").attr("data-src"));
//所需链接在
中的a标签里面
Elements url = doc.select("div.detail").select("a");
Log.i("mytag", "url:" + url.get(i).attr("href"));
//原料在

Elements burden = doc.select("p.subcontent");
//对于一个元素中的文本,可以使用Element.text()方法
Log.i("mytag", "burden:" + burden.get(1).text());
}catch(Exception e) {undefined
Log.i("mytag", e.toString());
}
大功告成,接下来看看log
Paste_Image.png
没有问题!那么教学可以结束了!
注意:
Jsoup.connect(String url)方法不能运行在主线程,否则会报NetworkOnMainThreadException

F. Android studio中,用get方法获取网页源代码,怎么做

< form id="form1" method="get" runat="server"> get方法提交表单 < div> 你的名字< asp:TextBox ID="name" runat="server">< /asp:TextBox>< br /> < br /> 你的网站< asp:TextBox ID="website" runat="server">< /asp:TextBox>< br /> < br /> < br /> < asp:Button ID="Button1" runat="server" Text="send" />< br /> < br /> < br /> 学习request 和 response的用法< br /> < br /> < br /> < /div> < /form> ----------------------------------------------------------------------------------------------------------- < form id="form2" method="post" runat="server"> post方法提交表单 < div> 你的名字< asp:TextBox ID="name2" runat="server">< /asp:TextBox>< br /> < br /> 你的网站< asp:TextBox ID="website2" runat="server">< /asp:TextBox>< br /> < br /> < br /> < asp:Button ID="Button2" runat="server" Text="send" />< br /> < br /> < br /> 学习request 和 response的用法< br /> < br /> < br /> < /div> < /form> 1. get是从服务器上获取数据,post是向服务器传送数据。 2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。post是通过HTTP post机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。 3. 对于get方式,服务器端用Request.QueryString获取变量的值,对于post方式,服务器端用Request.Form获取提交的数据。 4. get传送的数据量较小,不能大于2KB。post传送的数据量较大,一般被默认为不受限制。 5. get安全性非常低,post安全性较高。但是执行效率却比Post方法好。 建议: 1、get方式的安全性较Post方式要差些,包含机密信息的话,建议用Post数据提交方式; 2、在做数据查询时,建议用Get方式;而在做数据添加、修改或删除时,建议用Post方式

G. Android 在WebView中通过javascript获取网页源码,并在TextView或者在EditText中显示问题

webview js之间的交互,项目中马上用到。

JS调用java代码效果图


index.html代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd";><html><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" language="javascript"> var share = JSON.stringify({"title": "sinodata",
"desc": "ios",
"shareUrl": "http://www.sinodata.com.cn"
});

function sendInfoToJava(){
window.AndroidWebView.showInfoFromJs(share);
}

<!--在android代码中调用此方法-->
function showInfoFromJava(msg){
alert("showInfoFromJava:"+msg);
} </script></head><body la><div id='b'> <input onclick="sendInfoToJava()" type="button" value="sendInfoToJava"/></div></body></html>
布局代码:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.chenjifang.webview.MainActivity"> <Button android:id="@+id/test_btn" android:text="代码中调用web js代码传递参数" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/test_edt" android:layout_width="match_parent" android:layout_height="wrap_content" /><WebView android:id="@+id/test_webview" android:layout_width="match_parent" android:layout_height="400dp"></WebView></LinearLayout>
java代码:

public class MainActivity extends AppCompatActivity {private WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mWebView = (WebView) findViewById(R.id.test_webview); //设置WebView支持JavaScript mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl("file:///android_asset/index.html"); mWebView.addJavascriptInterface(new JsInterface(this), "AndroidWebView"); //添加客户端支持 mWebView.setWebChromeClient(new WebChromeClient()); findViewById(R.id.test_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
sendInfoToJs(); }
}); } private class JsInterface { private Context mContext; public JsInterface(Context context) { this.mContext = context; } //在js中调用window.AndroidWebView.showInfoFromJs(name),便会触发此方法。 @JavascriptInterface public void showInfoFromJs(String share) {
Toast.makeText(mContext, share, Toast.LENGTH_SHORT).show(); }
} //在java中调用js代码 public void sendInfoToJs() {
String msg = ((EditText)findViewById(R.id.test_edt)).getText().toString(); //调用js中的函数:showInfoFromJava(msg) mWebView.loadUrl("javascript:showInfoFromJava('" + msg + "')"); }
总结下,java代码中要设置webview对javascript的支持,addJavascriptInterface(new JsInterface(this), "AndroidWebView");//这句代码中的第二个参数是在js访问方法的地址。
window.AndroidWebView.showInfoFromJs(share);

H. android获取网页源码,只能获取当前屏幕大小的HTML源码,后面的要怎么显示出来

在Androidmanifest.xml里添加以下两行就ok.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
then.就口以添加关于抓取网页的代码了。主要就是俩函数,一个负责连接网页(testGetHtml()),一个用于读取源码(readStream()):
public static byte[] readStream(InputStream inputStream) throws Exception {
byte[] buffer = new byte[1024];
int len = -1;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
while ((len = inputStream.read(buffer)) != -1) {
byteArrayOutputStream.write(buffer, 0, len);
}
inputStream.close();
byteArrayOutputStream.close();
return byteArrayOutputStream.toByteArray();
}
public static String testGetHtml(String urlpath) throws Exception {
URL url = new URL(urlpath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(6 * 1000);
conn.setRequestMethod("GET");
if (conn.getResponseCode() == 200) {
InputStream inputStream = conn.getInputStream();
byte[] data = readStream(inputStream);
String html = new String(data);
return html;
}
return null;
}
用的时候注意URL要写全,testGetHtml("http://www..com/")这样即可。
源码会存在一个String变量中

I. 如何获取android源代码

当前的Android代码托管在两个方:https://github.com/android 和https://android.googlesource.com之前在 android.git.kernel.org上也有托管,不过现在重定向到了https://android.googlesource.com好在都支持git访问。

google提供的repo工具实际上是一个内部操作git工具来简化操作Android源码的Python脚本。经过尝试,直接使用git工具在ubuntu下可以实现cloneAndroid源码。下面介绍一下方法:

1.获取当前的在github上托管的Androidgitrepositories:

github页面为:https://github.com/android/following。不过这个页面不支持通过wget"https://github.com/android/following"或者curl"https://github.com/android/following"的方式访问,错误信息如下:

这个时候需能做的只能是"tryagain"了。

需要说明的是"不要试图同时并发执行多个gitclone命令",这样会导致大量出现上面贴图中的错误,另外,整个clone过程中耗时最多的gitrepository如下:

kernel_common.gitkernel_msm.gitplatform_frameworks_base.gitplatform_prebuilt.git其中platform_prebuilt.git是google提供的预编译好的二进制文件,包含:各种库文件,jar包,可执行程序等等,如果只是阅读Android源代码,这个gitrepository可以不用clone.

J. 有没有可以在 iOS 和 Android 上查看网页源码的浏览器

Android
上的
Firefox
可以在地址栏里的原URL前加
view-source:
即可查看源代码。
加装这个插件会新开一个标签来查看源代码,更方便些。
View
Source
Mobile
View
Source
Mobile
::
Add-ons
for
Firefox
for
Android
另外
@Bill
Cheng
:
Android
上的
Firefox
暂时还没有
FireBug

热点内容
我的世界搭建无正版验证服务器 发布:2024-05-05 17:03:48 浏览:817
我的世界服务器地址宝可梦 发布:2024-05-05 17:00:16 浏览:254
dede企业源码 发布:2024-05-05 16:57:53 浏览:786
如何查看java版本 发布:2024-05-05 16:45:05 浏览:494
转子绕组电动机控制柜如何配置 发布:2024-05-05 16:45:04 浏览:917
搭建游戏要多大服务器 发布:2024-05-05 16:44:16 浏览:346
云服务器ecs网站 发布:2024-05-05 16:35:55 浏览:563
c语言打印正方形 发布:2024-05-05 16:09:20 浏览:643
编程用箭头 发布:2024-05-05 15:54:21 浏览:794
步骤条源码 发布:2024-05-05 15:35:55 浏览:846