dongtuhe0506 2015-06-16 11:04
浏览 65
已采纳

如何将“查看页面源代码”复制到新文件中? [关闭]

When you right click here. you will find 'View Page Source' on clicking that, a new window opens with source code of that page.

My question is how would I copy those source code into new file either using javascript , jquery or using php.

  • 写回答

1条回答 默认 最新

  • dongzou1964 2015-06-16 11:10
    关注

    Using jQuery:

    $.get( "http://www.example.com/", function( data ) {
      console.log(data);
    });
    

    Using PHP:

    $homepage = file_get_contents('http://www.example.com/');
    print_r($homepage);
    

    Reading from a URL and writing to a file:

    file_put_contents('example_site.html', file_get_contents('http://www.example.com'));
    

    Note: Make sure you have write permissions in the directory where you are exporting this file to.

    To display HTML data without browser rendering it:

    $html= "<h1>Hello</h1>";
    echo htmlspecialchars($html);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启