基于PHP采集数据入库程序(一),php采集数据入库
基于PHP采集数据入库程序(一),php采集数据入库
前几天有一朋友要我帮做一个采集新闻信息的程序,抽了点时间写了个PHP版本的,随笔记录下。
说到采集,无非就是远程获取信息->提取所需内容->分类存储->读取->展示
也算是简单"小偷程序"的加强版吧
下面是对应核心代码(别拿去做坏事哦^_^)
所要采集的内容是某游戏网站上的公告,如下图:
可先利用file_get_contents和简单正则获取基本页面信息
整理下基本信息,采集入库:
<?<span>php </span><span>include_once</span>("conn.php"<span>); </span><span>if</span>(<span>$_GET</span>['id']<=8&&<span>$_GET</span>['id'<span>]){ </span><span>$id</span>=<span>$_GET</span>['id'<span>]; </span><span>$conn</span>=<span>file_get_contents</span>("http://www.93moli.com/news_list_4_<span>$id</span>.html");<span>//</span><span>获取页面内容</span> <span>$pattern</span>="/<li><a title=\"(.*)\" target=\"_blank\" href=\"(.*)\">/iUs";<span>//</span><span>正则</span> <span>preg_match_all</span>(<span>$pattern</span>, <span>$conn</span>, <span>$arr</span>);<span>//</span><span>匹配内容到arr数组 //print_r($arr);die;</span> <span>foreach</span> (<span>$arr</span>[1] <span>as</span> <span>$key</span> => <span>$value</span>) {<span>//</span><span>二维数组[2]对应id和[1]刚好一样,利用起key</span> <span>$url</span>="http://www.93moli.com/".<span>$arr</span>[2][<span>$key</span><span>]; </span><span>$sql</span>="insert into list(title,url) value ('<span>$value</span>', '<span>$url</span>')"<span>; </span><span>mysql_query</span>(<span>$sql</span><span>); </span><span>//</span><span>echo "<a href='content.php?url=http://www.93moli.com/$url'>$value</a>"."<br/>"; </span> <span> } </span><span>$id</span>++<span>; </span><span>echo</span> "正在采集URL数据列表<span>$id</span>...请稍后..."<span>; </span><span>echo</span> "<script>window.location='list.php?id=<span>$id</span>'</script>"<span>; }</span><span>else</span><span>{ </span><span>echo</span> "采集数据结束。"<span>; } </span>?>
conn.php是数据库连接文件
list.php是本页面
由于要采集的数据是分页显示的,且页面地址是规律递增,所以我用了js跳转代码,利用id传值控制采集的页数,也避免了for循环数目过大。
轻轻松松数据入库,下篇博客写关于具体url采集信息的过程。
php数据采集常见技术要领:
1、熟练正则表达式提取数据技术:提取内容关键步骤
2、熟练字符编码转换分析技术:兼容性管理以及数据有效性控制
3、熟练数据出库入库整理技术:对已采集内容的存储管理,包括数据库以及文件和进度
4、发掘数据以及网站爬行技术:分析网站结构,简化爬行手法,提高效率
5、反反采集处理技术:对于存在反采集的目标对象而设计的反反采集技术
6、多服务器并发采集管理技术:提高效率的工作方法
7、数据整理分析技术:查漏验证数据正确性有效性
8、自我身份保护技术:自身信息的保护
phpquery 用这个,自己再写个入库,

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

How to write a perfect PHP programmer resume In a highly competitive job market, an excellent resume is crucial for job seekers. For PHP programmers, writing a perfect resume is particularly important, because the resume is not only a window to showcase your skills and experience, but also the key to attracting the employer's attention. This article will explain in detail how to write a perfect PHP programmer job resume from beginning to end. Step One: Choose a Concise and Attractive Resume Template Choosing a concise and attractive resume template is the first step in writing your resume.

Don't be ignored anymore! Learn How to Design an Impressive PHP Programmer Resume In today's competitive job market, having an impressive resume is key to landing your dream job. Especially for technical positions such as PHP programmers, resumes are a window to showcase your skills and experience. This article will teach you how to design an impressive PHP programmer resume, complete with code examples. First, a good resume will attract the reader's attention. The title should succinctly describe your

Improve job search success rate: Tips for writing an excellent PHP programmer job resume In modern society, job hunting has become an important task faced by every graduate. When it comes to applying for a job, your resume is the most important piece. An excellent resume can win you an interview and even determine whether you can successfully get a job. Especially for a highly competitive position like PHP programmer, how to write an outstanding resume has become a key issue for every job seeker. Below I will share some tips for writing an excellent PHP programmer job resume.

How to write a PHP programmer resume that will impress employers. In the highly competitive job market, it is particularly important to write an excellent resume. As a PHP programmer, in addition to your impressive work experience and skills, a resume also needs to reflect your love for programming and solid professional knowledge. This article will introduce some tips and code examples to help you write a PHP programmer resume that will shine in the eyes of employers. Concise and clear personal information The personal information section of your resume should include your name, contact information and personal website

Eye-catching resume tips for PHP programmers: How to stand out from other candidates With the rapid development of the Internet industry, PHP programmers have also become one of the popular positions in the job market. However, more and more people are choosing PHP as their career development direction, which makes the competition more intense. Under such circumstances, how to make your resume stand out and become popular in the eyes of employers is a question that every PHP programmer needs to think about. First, a good resume should clearly and concisely demonstrate your skills.

The road to high-paying counterattack for PHP programmers. With the rapid development of the Internet, the demand in the field of computer science continues to increase. In this era, people who need programming skills are most in demand. As a commonly used programming language, PHP provides programmers with a high-paying counterattack path. This article will introduce how PHP programmers can move towards a high-paying counterattack by learning PHP and related technologies, and attach some code examples. 1. Master the basic knowledge of PHP. To become an excellent PHP programmer, you first need to master the basic knowledge of PHP.

Explore Writing Tips: How to Write a Compelling PHP Programmer Resume In today's competitive job market, a compelling resume is especially important for PHP programmers. A good resume not only catches the employer's eye but also showcases your skills and experience. This article will explore some writing tips to help you craft a great PHP programmer resume, complete with code examples that highlight your professional abilities. Concise and clear format The format of your resume should be concise and clear, allowing employers to quickly scan your relevant information.

In today's highly competitive job market, how to stand out from the crowd of job seekers has become a very important issue. Especially for PHP programmers, a good resume can directly affect whether you can get an interview. This article will give you a detailed introduction to how to write a PHP programmer resume that makes you stand out. First of all, a good job resume should contain the following important parts: personal information, job intention, educational background, work experience, skills and expertise, and personal project experience. We will go part by part
