源代码和DOM有什么区别? [英] What is the difference between source code and DOM?

查看:193
本文介绍了源代码和DOM有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 在我的应用程序中,我想处理谷歌翻译定义,如单词song的定义






  • 当我检查返回的http消息时,它不包含short poem
    表达式。


< img src =https://i.stack.imgur.com/E2oDp.pngalt =在这里输入图片描述>




  • 但是在Safari的DOM树视图中,我可以看到短诗信息。





  • 这是因为加载页面后JavaScript代码做了
    的魔术?如何在iOS应用程序中获得 DOM树 UIWebView 可以做
    这么神奇吗?

解决方案

页面源代码和页面DOM之间的概念是相似的,但不同。源代码是未被任何客户端脚本伪装的原始HTML。这是HTTP请求对服务器的直接响应。另一方面,DOM是由JavaScript修改的相同的HTML结构。



源代码读取页面的HTML,就像在文本编辑器中打开它一样。在加载任何JavaScript之前,源代码反映了您的HTML结构。尽管无法编辑内容,但看到HTML Safari从服务器接收信息很有用。 $ b

https://developer.apple.com/library/mac/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/ResourcesandtheDOM/ResourcesandtheDOM .html



希望它对您有所帮助。

编辑:尝试阅读关于API的信息,我认为有翻译和API的API

  • In my app I want to process Google Translate definitions, like definition for the word "song"

  • When I check returned http message, it does NOT contain the "short poem" expression.

  • But in DOM tree view in Safari I can see the "short poem" info.

  • This is because after loading page some JavaScript code do some magic? How would you get DOM tree in an iOS app? UIWebView can do such a magic?

解决方案

The notions between a page’s source and a page’s DOM are similar, but different. The source is the raw HTML that is unadulterated by any client-side scripts. It is the direct response of the HTTP request to the server. The DOM, on the other hand, is the same HTML structure that has been modified by JavaScript.

Source Code reads the page’s HTML as if you opened it in a text editor. The source code reflects your HTML structure before any JavaScript is loaded. While the contents can’t be edited, it’s useful to see the HTML Safari receives from the server.

https://developer.apple.com/library/mac/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/ResourcesandtheDOM/ResourcesandtheDOM.html

Hope it helps you.

Edit: Try to read about API, I think there are API's for translate and stuff

这篇关于源代码和DOM有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆