Table of Contents
回复内容:
Home Backend Development PHP Tutorial php抓取js动态加载的内容,请教下

php抓取js动态加载的内容,请教下

Jun 06, 2016 pm 08:42 PM
php

请假下大家,如何用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咯。

以上如有错误,欢迎指正。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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 Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

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.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

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

See all articles