GVKun编程网logo

php – 更好地获取页面的html源(php获取html页面内容)

13

在本文中,您将会了解到关于php–更好地获取页面的html源的新资讯,同时我们还将为您解释php获取html页面内容的相关在本文中,我们将带你探索php–更好地获取页面的html源的奥秘,分析php获

在本文中,您将会了解到关于php – 更好地获取页面的html源的新资讯,同时我们还将为您解释php获取html页面内容的相关在本文中,我们将带你探索php – 更好地获取页面的html源的奥秘,分析php获取html页面内容的特点,并给出一些关于asp.net – 如何获取当前页面的HTML?、asp.net-mvc – 使用cshtml页面的angularjs不是带有web api 2的html页面、html - php怎么获取页面上的超链接并补齐成全地址?、html获取页面传参id的实用技巧。

本文目录一览:

php – 更好地获取页面的html源(php获取html页面内容)

php – 更好地获取页面的html源(php获取html页面内容)

我试图通过过滤其源代码来获取网页上的一些数据,我找到了很多方法来获取网页的html内容,例如$html = file_get_html(‘http://www.exam.com/results /’); ,curl,html获取源代码.

获取页面的html源代码的最佳方法是什么?或者所有这些方法都相同?

解决方法:

cURL可以提供比file_get_contents($url)*****更好的性能.
我宁愿使用cURL,因为所有这些函数最终都会检索某个网页内容,唯一的区别就是我说的运行时使用cURL时效果更好.

*你可以在这里找到一个体面的(但不是正式的)证明,包括基准:
https://stackoverflow.com/questions/555523/file-get-contents-vs-curl-what-has-better-performance

asp.net – 如何获取当前页面的HTML?

asp.net – 如何获取当前页面的HTML?

我想解析当前页面的html.
如何在asp.net中获取当前页面的html?

提前致谢.

解决方法

对于客户方

在Internet Explorer中

右键单击浏览器 – >查看来源

在Firefox中

右键单击浏览器 – >查看页面源代码

对于服务器端

您可以覆盖页面的render方法以捕获服务器端的HTML源代码.

protected override void Render(HtmlTextWriter writer)
{
    // setup a TextWriter to capture the markup
    TextWriter tw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(tw);

    // render the markup into our surrogate TextWriter
    base.Render(htw);

    // get the captured markup as a string
    string pageSource = tw.ToString();

    // render the markup into the output stream verbatim
    writer.Write(pageSource);

    // remove the viewstate field from the captured markup
    string viewStateRemoved = Regex.Replace(pageSource,"<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\".*?\" />","",RegexOptions.IgnoreCase);

    // the page source,without the viewstate field,is in viewStateRemoved
    // do what you like with it
}

asp.net-mvc – 使用cshtml页面的angularjs不是带有web api 2的html页面

asp.net-mvc – 使用cshtml页面的angularjs不是带有web api 2的html页面

我有asp. net mvc4项目. Angularjs是整合的.
我已经按照以前的要求构建了HTML页面和WEB API 2.

现在由于某种原因,我必须使用CSHTML页面.以前我只有web api项目模板所以我不能用cshtml页面,因为只有MVC控制器可以返回部分页面(cshtml),但我只使用web apis …

所以改变了整个项目模板,所以现在我可以拥有mvc控制器……

总之,目前我已经建立了web apis和html页面的mvc4项目…..

我只是想使用CSHTML页面而不是使用HTML页面休息的东西应该是它们……

可能吗?

我可能听起来很傻但现在需要它.帮助将不胜感激……

仅限Web apis,cshtml页面和angularjs.不是web apis,html pages和angularjs.

如果我用cshtml替换html页面,角度路由会受到什么影响?

解决方法

嗯,这就是我使用它的方式.

有像这样的index.cshtml

@using System.Web.Optimization
@inherits System.Web.Mvc.WebViewPage
@{ Layout = null; }<!DOCTYPE html>
<html data-ng-app="MyProject">
<head>
    <title data-ng-controller="TitleCtrl" data-ng-bind="Title">My Project</title>
    <Meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <Meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <Meta http-equiv="cache-control" content="max-age=0" />
    <Meta http-equiv="cache-control" content="no-cache" />
    <Meta http-equiv="expires" content="0" />
    <Meta http-equiv="expires" content="Tue,01 Jan 1980 1:00:00 GMT" />
    <Meta http-equiv="pragma" content="no-cache" />

    @Styles.Render("~/Content/min/css")
</head>
<bodyid="body">

    <divdata-ui-view="body"></div>

    @Scripts.Render("~/js/angular")
    @Scripts.Render("~/js/MyProject")
</body>
</html>

注意:使用角度UI-Router,这就是ui-view所在的原因

但仍然必须有HomeController:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        // below I do some tricks to make app running on 
        // http://mydomain/app as well as on
        // http://mydomain/app/  (see the / at the end)

        var root = VirtualPathUtility.ToAbsolute("~/");
        var applicationPath = Request.ApplicationPath;
        var path = Request.Path;
        var hasTraillingSlash = root.Equals(applicationPath,StringComparison.InvariantCultureIgnoreCase)
                || !applicationPath.Equals(path,StringComparison.InvariantCultureIgnoreCase);
        if (!hasTraillingSlash)
        {
            return Redirect(root + "#");
        }

        // my view is not in Views,but in the root of a web project
        return View("~/Index.cshtml");
    }
}

所以,这样我可以使用Bundle配置(javascript,css)的功能……同时在http:// mydomain / app或http:// mydomain / app /启动角度.检查类似here

同样在global.asax中,我们应该配置ASP.NET MVC:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.IgnoreRoute("fonts*.woff");

    routes.MapRoute(
      name: "Default",url: "{controller}/{action}/{id}",defaults: new {controller = "Home",action = "Index",id =UrlParameter.Optional}
    );
}

而web API应该是:

const string IdPattern = @"\d+|[A-Za-z]{1,2}";
public static void SetRouting(HttpConfiguration config)
{
    // some custom routes
    ...            

    // and a default one
    config.Routes.MapHttpRoute(
        name: "DefaultApi",routeTemplate: "api/{controller}/{id}",constraints: new { id = IdPattern },defaults: new { id = RouteParameter.Optional }
    );

html - php怎么获取页面上的超链接并补齐成全地址?

html - php怎么获取页面上的超链接并补齐成全地址?

curl获取一个网站解析其中的a标签会得到链接,有的会是http:// 这样完整的,有的会是/about,../about相对的,有的是#,javascript之类的,怎么将匹配的链接全部补齐为完整链接(域名加相对的),锚点和js的排除掉?

回复内容:

curl获取一个网站解析其中的a标签会得到链接,有的会是http:// 这样完整的,有的会是/about,../about相对的,有的是#,javascript之类的,怎么将匹配的链接全部补齐为完整链接(域名加相对的),锚点和js的排除掉?

自己写个方法计算就行了。例如请求 http://example.com/qa/list.php, 其中主机地址是 http://example.com, 目录地址是 http://example.com/qa/
如果地址是 http(s)://开头,完整地址
如果地址是/开头, 如 /aboutus,完整地址是主机地址+该地址,即 http://example.com/aboutus
如果地址是其它开头,如 ../aboutus, 完整地址是目录地址+该地址,即 http://example.com/qa/../aboutus
如果你觉得../很碍眼,可以自己整理一下,每个../抵消一级父目录,变成 http://example.com/aboutus

/**
 * 返回当前请求的完整URL
 *
 * @return string
 */
function current_url()
{
    $host = $_SERVER[''HTTP_HOST''];
    $uri = $_SERVER[''REQUEST_URI''];

    return (is_https() ? ''https://'' : ''http://'') . $host . $uri;
}
登录后复制

好吧,看错题目了。。。

关于处理相对路径的问题可以参考我之前写过的一篇文章:http://blog.icewingcc.com/php-conv-addr-re-ab-2.html

立即学习“PHP免费学习笔记(深入)”;

html获取页面传参id

html获取页面传参id

@html获取页面传参id 

var url=window.location.search;//获取 href 属性中跟在问号后面的部分
var id = url.substring(url.lastIndexOf(''='')+1, url.length);//截取等号后面的部分

 

关于php – 更好地获取页面的html源php获取html页面内容的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于asp.net – 如何获取当前页面的HTML?、asp.net-mvc – 使用cshtml页面的angularjs不是带有web api 2的html页面、html - php怎么获取页面上的超链接并补齐成全地址?、html获取页面传参id等相关知识的信息别忘了在本站进行查找喔。

本文标签: