php抓取js动态加载的内容,请教下
请假下大家,如何用php抓取 页面上 js动态加载来的内容,
file_get_contents 只能获取 用查看源码看到的源码,,其实页面上还有别的内容,请大家给些建议..
回复内容:
请假下大家,如何用php抓取 页面上 js动态加载来的内容,
file_get_contents 只能获取 用查看源码看到的源码,,其实页面上还有别的内容,请大家给些建议..
碰巧最近在琢磨类似的功能,虽然还没有实践,但是也来说下个人见解吧
js动态加载的内容如何抓取,我觉得可以分2种情况
第一种:加载的内容通过ajax请求的,那么可以在控制台看下请求的是哪个url,返回的是什么结果,js是怎么样把返回的结果处理后附加到dom上的,然后自己也去抓取那个url再解析下就行了,如果是需要登陆后才能抓的,那就带上cookie就好了
第二种:加载的内容是无需发起ajax请求的,而是根据已存在的内容经过处理后加载的,比如说当前js里的变量,dom里的内容,这个就得去看代码分析了...
还有的方法就是装个能解析js的php扩展...像V8js啊,php_js_ext啊都可以试试,把核心js改动下丢进去跑,个人觉得这个方法很蛋疼,浪费时间,不过具体情况具体分析吧
php无法执行js代码,这个你得用phantomjs
file_get_contents 顾名思义抓取得是file里面的内容。
而页面(file)都是在浏览器加载后转变成DOM,同样页面上js动态加载来的内容也是DOM(其并没有改变页面本身),所以自然file_get_contents无法取到。
要取js动态加载来的内容,当然解铃还须系铃人,使用js原生方法或者jQuery咯。
以上如有错误,欢迎指正。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an
