search
HomeBackend DevelopmentPHP TutorialProgram for collecting data into the database based on PHP (2), collecting data into the database with PHP_PHP tutorial

PHP-based data collection and warehousing program (2), PHP data collection and warehousing

In the previous article, PHP-based data collection and warehousing program (2) mentioned the collection of news information Page list data, let’s talk about the specific content of collecting news

This is the screenshot of the final data sheet from the previous blog:

The next step is to read the URL that needs to be collected from the database and crawl the page

Create a new content table

However, one thing to note is that you can no longer use the incrementing method of collecting URLs, because there may be id discontinuities in the data table, such as id=9, id=11. When the id=10 is collected, Sometimes, the URL is blank, which may result in empty fields being collected.

One of the techniques used here is the query statement of the database. When we collect the first piece of data, we determine whether there is an ID number greater than this ID in the database. If so, read one and repeat the query information above. work.

The specific code is as follows:

<?<span>php
    
    </span><span>include_once</span>("conn.php"<span>);
    </span><span>$id</span>=(int)<span>$_GET</span>['id'<span>];
    </span><span>$sql</span>="select * from list where id=<span>$id</span>"<span>;
    </span><span>$result</span>=<span>mysql_query</span>(<span>$sql</span><span>);
    </span><span>$row</span>=<span>mysql_fetch_array</span>(<span>$result</span>);<span>//</span><span>取得对应的url地址</span>
    <span>$content</span>=<span>file_get_contents</span>(<span>$row</span>['url'<span>]);
    </span><span>$pattern</span>="/<dd class=\"dataWrap\">(.*)<\/dd>/iUs"<span>;
    </span><span>preg_match</span>(<span>$pattern</span>, <span>$content</span>,<span>$info</span>);<span>//</span><span>获取内容存放info</span>
    <span>echo</span> <span>$title</span>=<span>$row</span>[1]."<br/>"<span>;
    </span><span>echo</span> <span>$content</span>=<span>$info</span>[0]."<hr/>"<span>;

    </span><span>//</span><span>插入数据库</span>
    <span>$add</span>="insert into content(title,content) value('<span>$title</span>','<span>$content</span>')"<span>;
    </span><span>mysql_query</span>(<span>$add</span><span>);

    </span><span>$sql2</span>="select * from list where id><span>$id</span> order by id asc limit 1"<span>;
    </span><span>$result2</span>=<span>mysql_query</span>(<span>$sql2</span><span>);
    </span><span>$row2</span>=<span>mysql_fetch_array</span>(<span>$result2</span>);<span>//</span><span>取得对应的url地址</span>
    <span>if</span>(<span>$row2</span>['id'<span>]){
        </span><span>echo</span> "<script>window.location='content.php?id=<span>$row2</span>[0]'</script>"<span>;
    }

</span>?>

In this way, the news content we want has been collected and stored in the database. Next, we only need to organize some styles of the data.

How well do PHP programmers understand data collection?

Common technical essentials for PHP data collection:

1. Proficient in regular expression data extraction technology: key steps for extracting content
2. Proficient in character encoding conversion analysis technology: compatibility management and data validity control
3. Proficient in data storage and storage technology: storage and management of collected content, including databases, files and progress
4. Data mining and website crawling technology: analyze website structure, simplify crawling techniques, and improve efficiency
5. Anti-anti-collection processing technology: Anti-anti-collection technology designed for target objects with anti-collection
6. Multi-server concurrent collection management technology: working methods to improve efficiency
7. Data sorting and analysis Technology: Check for leaks and verify the correctness and effectiveness of data
8. Self-identity protection technology: Protection of one’s own information

PHP collection and warehousing problem

There is $nr = implode('#',$arr) method in php, that's it
But the above composition is "Content 1# Content 2" without the last #, if necessary
That’s $nr = implode('#',$arr).'#'

The stupid way is to use
foreach( $arr as $vl){
$nr .=$vl."#";
}
Reference: $

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/850753.htmlTechArticleBased on PHP data collection and warehousing program (2), PHP data collection and warehousing is in the previous article based on PHP data collection and warehousing. The library program (2) mentioned collecting list data of news information pages, let’s talk about it next...
Statement
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
从头到尾详解:如何撰写一份完美的PHP程序员求职简历从头到尾详解:如何撰写一份完美的PHP程序员求职简历Sep 10, 2023 pm 04:21 PM

如何撰写一份完美的PHP程序员求职简历在竞争激烈的就业市场中,一份出色的简历对于求职者来说是至关重要的。对于PHP程序员来说,撰写一份完美的简历尤为重要,因为简历不仅是展示自己技能和经验的窗口,也是吸引雇主注意力的关键。本文将从头到尾详解如何撰写一份完美的PHP程序员求职简历。第一步:选择简洁而具有吸引力的简历模板选择一份简洁而具有吸引力的简历模板是撰写简历

提高求职成功率:写一份优秀的PHP程序员求职简历的技巧提高求职成功率:写一份优秀的PHP程序员求职简历的技巧Sep 10, 2023 pm 06:30 PM

提高求职成功率:写一份优秀的PHP程序员求职简历的技巧在现代社会中,求职已经成为每个毕业生面临的一项重要任务。当谈到求职时,简历是最重要的一环。一份优秀的简历可以为你赢得面试的机会,甚至决定你能否成功获得工作。特别对于PHP程序员这样一个高度竞争的职位来说,如何写一份出众的求职简历,成为每个求职者的关键问题。下面我将分享一些写一份优秀的PHP程序员求职简历的

如何写出一份令雇主眼前一亮的PHP程序员求职简历如何写出一份令雇主眼前一亮的PHP程序员求职简历Sep 08, 2023 am 08:19 AM

如何写出一份令雇主眼前一亮的PHP程序员求职简历在竞争激烈的求职市场上,编写一份出色的简历尤为重要。作为PHP程序员,除了令人印象深刻的工作经历和技能,一份简历中也需要体现出你对编程的热爱和扎实的专业知识。本文将介绍一些技巧和代码示例,帮助你编写一份令雇主眼前一亮的PHP程序员求职简历。简洁明了的个人信息简历的个人信息部分应该包括你的姓名、联系方式和个人网站

抢眼的PHP程序员求职简历技巧:如何与其他候选人脱颖而出抢眼的PHP程序员求职简历技巧:如何与其他候选人脱颖而出Sep 12, 2023 am 10:16 AM

抢眼的PHP程序员求职简历技巧:如何与其他候选人脱颖而出随着互联网行业的快速发展,PHP程序员也成为了求职市场上的热门岗位之一。然而,越来越多的人选择了PHP作为自己的职业发展方向,这就使得竞争变得更加激烈。在这样的情况下,如何让自己的求职简历脱颖而出,成为雇主眼中的香饽饽,是每个PHP程序员都需要思考的问题。首先,一个好的求职简历应该清晰、简明地展示你的技

PHP程序员的高薪逆袭之路PHP程序员的高薪逆袭之路Sep 09, 2023 am 09:22 AM

PHP程序员的高薪逆袭之路随着互联网的快速发展,计算机科学领域的需求不断增加。在这个时代,需要具备编程技能的人才是最受欢迎的。而PHP作为一种常用的编程语言,为程序员们提供了一条高薪逆袭的道路。本文将介绍PHP程序员如何通过学习PHP以及相关技术,走向高薪逆袭之路,并附上一些代码示例。一、掌握PHP基础知识要成为一名优秀的PHP程序员,首先需要掌握PHP的基

别再被忽视了!学习如何设计一份令人印象深刻的PHP程序员求职简历别再被忽视了!学习如何设计一份令人印象深刻的PHP程序员求职简历Sep 08, 2023 pm 04:30 PM

别再被忽视了!学习如何设计一份令人印象深刻的PHP程序员求职简历在如今竞争激烈的就业市场中,拥有一份令人印象深刻的求职简历是找到理想工作的关键。尤其是对于PHP程序员这样的技术岗位来说,简历是展示自己技能和经验的窗口。本文将带你学习如何设计一份令人印象深刻的PHP程序员求职简历,并附上代码示例。首先,一个好的简历会吸引阅读者的注意力。标题应该简明扼要地说明你

探索写作技巧:如何撰写一份引人注目的PHP程序员求职简历探索写作技巧:如何撰写一份引人注目的PHP程序员求职简历Sep 09, 2023 pm 04:09 PM

探索写作技巧:如何撰写一份引人注目的PHP程序员求职简历在当今竞争激烈的就业市场中,一份引人注目的求职简历对于PHP程序员来说尤为重要。一个好的简历不仅能够吸引雇主的眼球,还能展示你的技能和经验。本文将探索一些写作技巧,帮助你撰写一份出色的PHP程序员求职简历,并附上代码示例,突出你的专业能力。简洁明了的格式简历的格式应该简洁明了,使得雇主能够快速浏览你的关

提高个人形象:如何写出一份让你脱颖而出的PHP程序员求职简历提高个人形象:如何写出一份让你脱颖而出的PHP程序员求职简历Sep 10, 2023 pm 05:12 PM

在当今竞争激烈的就业市场中,如何让自己在众多求职者中脱颖而出成为了一个非常重要的问题。尤其对于PHP程序员来说,良好的求职简历能够直接影响到是否能够得到面试的机会。本文将为大家详细介绍如何写出一份让你脱颖而出的PHP程序员求职简历。首先,一个好的求职简历应该包含以下几个重要部分:个人信息、求职意向、教育背景、工作经历、技能特长和个人项目经验等。我们将逐个部分

See all articles

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

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MantisBT

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.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.