来源:http://www.ido321.com/1158.html 抓取某一个网页中的内容,需要对DOM树进行解析,找到指定节点后,再抓取我们需要的内容,过程有点繁琐。LZ总结了几种常用的、易于实现的网页抓取方式,如果熟悉JQuery选择器,这几种框架会相当简单。 一、Ganon 项目
来源:http://www.ido321.com/1158.html
抓取某一个网页中的内容,需要对DOM树进行解析,找到指定节点后,再抓取我们需要的内容,过程有点繁琐。LZ总结了几种常用的、易于实现的网页抓取方式,如果熟悉JQuery选择器,这几种框架会相当简单。
一、Ganon
项目地址: http://code.google.com/p/ganon/
文档: http://code.google.com/p/ganon/w/list
测试:抓取我的网站首页所有class属性值是focus的div元素,并且输出class值
<span><?php <span>include</span> <span>'ganon.php'</span>; $html = file_get_dom(<span>'http://www.ido321.com/'</span>); <span>foreach</span>($html(<span>'div[class="focus"]'</span>) <span>as</span> $element) { <span>echo</span> $element-><span>class</span>, <span>"<br>\n"</span>; } ?>
结果:
二、phpQuery
项目地址:http://code.google.com/p/phpquery/
文档:https://code.google.com/p/phpquery/wiki/Manual
<span><?php <span>include</span> <span>'phpQuery/phpQuery.php'</span>; phpQuery::newDocumentFile(<span>'http://www.ido321.com/'</span>); $artlist = pq(<span>"article"</span>); <span>foreach</span>($artlist <span>as</span> $title){ <span>echo</span> pq($title)->find(<span>'h2'</span>)->html().<span>"<br>"</span>; } ?>
结果:

三、Simple-Html-Dom
项目地址:
http://simplehtmldom.sourceforge.net/
文档:
http://simplehtmldom.sourceforge.net/manual.htm
测试:抓取我网站首页的所有链接
<span><?php <span>include</span> <span>'simple_html_dom.php'</span>; <span>//使用url和file都可以创建DOM</span> $html = file_get_html(<span>'http://www.ido321.com/'</span>); <span>//找到所有图片</span> <span>// foreach($html->find('img') as $element)</span> <span>// echo $element->src . '<br>';</span> <span>//找到所有链接</span> <span>foreach</span>($html->find(<span>'a'</span>) <span>as</span> $element) <span>echo</span> $element->href . <span>'<br>'</span>; ?>
结果:(截图是一部分)

四、Snoopy
项目地址:http://code.google.com/p/phpquery/
文档:http://code.google.com/p/phpquery/wiki/Manual
测试:抓取我的网站首页
<span><?php <span>include</span>(<span>"Snoopy.class.php"</span>); $url = <span>"http://www.ido321.com"</span>; $snoopy = <span>new</span> Snoopy; $snoopy->fetch($url); <span>//获取所有内容</span> <span>echo</span> $snoopy->results; <span>//显示结果</span> <span>// echo $snoopy->fetchtext ;//获取文本内容(去掉html代码)</span> <span>// echo $snoopy->fetchlinks($url) ;//获取链接</span> <span>// $snoopy->fetchform ;//获取表单 </span> ?>
结果:

五、手动编写爬虫
如果编写能力ok,可以手写一个网页爬虫,实现网页抓取。网上有千篇一律的介绍此方法的文章,LZ就不赘述了。有兴趣了解的,可以百度 php 网页抓取。
ps:资源分享
常见的开源爬虫项目请戳:http://blog.chinaunix.net/uid-22414998-id-3774291.html
国民岳父的“屁民理论”

网页打不开的原因有:1、电脑的本地连接被禁用;2、拨号上网帐号与密码输入不正确;3、路由器故障或路由器设置出现问题;4、由DNS错误导致的IE打不开网页;5、hosts文件被修改导致的IE打不开网页;6、IP地址设置错误或者获取失败导致IE打不开网页。

使用JavaScript开发网页投票系统摘要:随着互联网的飞速发展,网上投票成为了一种方便快捷的方式,用于收集公众的意见和做出决策。本文将介绍使用JavaScript开发一个简单的网页投票系统,实现了用户可以选择选项并提交投票的功能。介绍:网页投票系统是一个在网页上显示多个选项并允许用户选择的程序。它可以用于许多场景,例如选举投票、产品调查、意见收集等。本文

网页无法访问的解决办法有检查网络连接、清除浏览器缓存、检查网页地址、尝试使用其他浏览器、检查服务器状态、检查域名解析、检查防火墙和安全设置和联系网站管理员等。详细介绍:1、检查网络连接,确保网络连接正常,可以尝试打开其他网页或者使用其他设备进行访问,确定是否是网络连接问题,如果其他网页可以正常访问,那么可能是该网页的问题;2、清除浏览器缓存,浏览器缓存可能导致网页无法加载等等。

网页打开慢解决方法:1、检查网络连接速度,可以使用在线测速工具来测试网络,可以联系网络服务提供商解决问题;2、可以通过清理浏览器缓存来改善网页打开速度,可以在浏览器的设置中找到清除缓存的选项,并选择清除所有缓存数据;3、在浏览器的插件和扩展程序管理页面,可以尝试禁用浏览器插件和扩展程序;4、网页打开慢还可能与电脑的性能有关,关闭占用系统资源的程序或进程也可以提高网页加载速度。

1、引言ChatGPT在当下已经风靡一时,作为自然语言处理模型的佼佼者,ChatGPT的优势在于其能够生成流畅、连贯的对话,同时还能够理解上下文并根据上下文进行回答。针对不同的应用场景可以进行快速定制,例如,在客服、教育、娱乐等领域中,ChatGPT可以作为智能助手为用户提供便捷的服务和娱乐体验。从GPT-3到GPT-4,我们可以看到在高级推理,输入设置,微调行为和理解更长的上下文信息等方面,ChatGPT在不断的优化训练中已经取得了显著的进展。但是针对于这种交互式的GPT模型,我们更希望看到能

在现代的网络应用中,自动刷新是一项非常有用的功能。通过使用JavaScript编程技术,您可以轻松实现网页自动刷新,以便在应用程序或网站中提供更好的用户体验。接下来,本篇文章将介绍如何使用JavaScript来实现网页自动刷新。使用setInterval函数setInterval函数是JavaScript中最常用的定时器函数之一。该函数允许在特定时间间隔内重

win10网络被禁用了怎么打开网页?使用win10系统的时候,发现网络被禁用了,就没有办法使用电脑,这种情况应该如何解决。很多小伙伴不知道怎么操作,小编下面整理了windows10网络被禁用了恢复教程,如果你感兴趣的话,跟着小编一起往下看看吧!win10网络被禁用了怎么打开1、在状态栏右边找到网络连接图标之后,右键点击它,然后选择“打开网络和Internet设置”选项并点击2、打开之后在出现的界面右边,找到并点击打开网络和共享中心3、点击更改适配器设置这个选项,找到被禁用的网络,右键点击它4、选

ChatGPT是一个超强的AI应用程序,OpenAI已经发布的GPT-4引起了更广泛的关注。ChatGPT是由OpenAI开发的专门从事对话的AI聊天机器人,其主要目标是使AI系统更自然地进行互动。大家可能都已经尝试过ChatGPT,今天讲一讲与这个全新工具互动的不同方法。本文总结了6个可以使ChatGPT成为日常助手(甚至超越日常助手)的工具!1.【GoogleChromeExtension】在任何地方使用ChatGPT想在任何地方轻松地使用ChatGPT吗?那么你可以使用Chrome插件(h


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

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
