问题

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 6 years ago.

I have an HTML table that I would like to parse in PHP to store into a MySQL Database. The HTML looks like this:

DATELOCATIONNAME

I would like to create a PHP function that returns in an array, the fields in capital letters. Does anyone know any php libraries that can do this, or should I be using a different language, as this may be complex. I don't know exactly how to do this with many tables on the page, but I am trying to parse the VEX events on RobotEvents. The table that I want to parse starts at line 465.

回答1:

As you're prepared to look beyond PHP, Nokogiri (Ruby) and Beautiful Soup (Python) are well-established libraries that parse HTML very well.

That doesn't imply that there are no suitable PHP libraries.

回答2:

Take a look at the PHP HTML DOM Parser library.

To use, you can do something similar to this (not my example):

require('simple_html_dom.php');

$table = array();

$html = file_get_html('http://flow935.com/playlist/flowhis.HTM');

foreach($html->find('tr') as $row) {

$time = $row->find('td',0)->plaintext;

$artist = $row->find('td',1)->plaintext;

$title = $row->find('td',2)->plaintext;

$table[$artist][$title] = true;

}

echo '

';

print_r($table);

echo '

';

There's some tutorials, SO questions and interesting reads about the library. It seems to be pretty popular.

http://davidwalsh.name/php-notifications

http://net.tutsplus.com/tutorials/php/html-parsing-and-screen-scraping-with-the-simple-html-dom-library/

Looping through a table with Simple HTML DOM

how to print cells of a table with simple html dom

UPDATE FOR FINDING SPECIFIC TABLE IN HTML USING ABOVE LIBRARY

To find a particular table amongst many:

1. By class:

On line 465 of your scraped HTML, the table starts with a class catalog-listing, so:

foreach ($html->find('table[@class="catalog-listing"]')->find('tr') as $row) {

// extract TD data

}

2. By instance (find 2nd table in HTML)

foreach ($html->find('table', 2)->find('tr') as $row) {

// extract TD data

}

来源:https://stackoverflow.com/questions/20724728/parse-html-table-php

php清理html table样式,Parse HTML Table - PHP [closed]相关推荐

  1. 还不错的Table样式和form表单样式

    作为一个后台开发人员而言,拥有一套属于自己的前台样式是比较重要的,这里分享一下自己感觉还不错的样式,以后遇到好的,还会陆续添加 上图: 带鼠标滑动效果的table样式看起来比较清爽 样式 <he ...

  2. table 样式详解

    1.table 中css样式控制border 只能控制外边框,内边框需要写<table border="1"> 2.table 会自动撑大,即使td 设置了 width ...

  3. 【CSS】Table样式

    一.table td的宽度详解 Table只有Table的宽度是可以设置的,并且各个浏览器理解一致 原则上应该将table的宽度设置成一个固定的值,而不应该设置成一个根据屏幕变化的值 Table的宽度 ...

  4. [转载] html转word table样式_[Python02] Python-docx包的使用,快速处理 Word 文件!

    参考链接: 通过Python-Docx模块在Python中读写MS Word文件 日常需要经常处理Word文档,发现了一个新的Python包:Python-docx,处理docx十分方便. 而且这个包 ...

  5. Html漂亮的table样式模板

    模板案例: table样式: <style scoped> table{border-collapse: collapse;margin: 0 auto;text-align: cente ...

  6. 手机端自适应表格table样式如何写

    有时候我们的网页需要展示一些表格的内容,在pc端是很好控制它的展现方式的,但是到移动端就非常难控制了,那么该怎么做呢? 比如上图就是没控制好的移动端的表格table样式,展示非常的凌乱. 这个就是写好 ...

  7. Bootstrap 之Table样式

    将<table>标签添加class='table' 类后的样式 <html> <head><meta name="viewport" co ...

  8. 去除bootstrap的table样式中单元格边框线

    使用bootstrap的table样式,在非纯白背景下,会有单元格边框线,影响美观. 去除方式: <style type="text/css">         bod ...

  9. html —— table 标签 与 display:table 样式

    目录: 一.table 相关标签介绍及使用 二.div 布局设置display:table 一.table 相关标签介绍及使用 相关标签按包含关系从大到小排序: table --> col | ...

最新文章

  1. Microsoft Surface Toolkit Beta 版发布
  2. ***:***之路的必备技能
  3. UGUI组件之ScrollRect 组件简单笔记(Scroll View)
  4. (剑指Offer)面试题22:栈的压入、弹出序列
  5. csv注入java怎么解决_CSV Injection(CSV注入)
  6. ubuntu中的日志文件位置,用于错误查找
  7. MySQL分组函数的使用特点
  8. linux主机开放ftp、http服务_Linux系统与Windows系统哪个好呢(一)
  9. centos8上安装nginx
  10. [vue] 使用vue渲染大量数据时应该怎么优化?说下你的思路!
  11. 福州大学c语言考试答案,C语言练习模拟考福州大学工程技术学院.doc
  12. pytorch 矩阵相乘_深度学习 — — PyTorch入门(三)
  13. c语言5的阶乘流程图_5 种前途迷茫的编程语言
  14. 英语词根词缀记忆法(全集)_闭着眼睛就能背好的托福词汇记忆法
  15. LINUX警告:检测到时钟错误。您的创建可能是不完整的。-转
  16. 基环树DP(bzoj 1040: [ZJOI2008]骑士)
  17. codeblocks报错Process terminated with status -1073741510 (0 minute(s), 3 second(s))
  18. python ppt自动生成目录_利用python-pptx库读写操作PPT,批量自动生成或修改的PPT
  19. bootstrap分辨率
  20. linux基础知识总结(二)

热门文章

  1. while嵌套注意事项(九九星号代码
  2. 知识图谱论文阅读(二十)【WWW2020】Heterogeneous Graph Transformer
  3. LayerNorm是Transformer的最优解吗?
  4. 机器学习从理论到工程的第一步-编程语言篇
  5. 综述 | 事件抽取及推理 (上)
  6. Android官方开发文档Training系列课程中文版:管理系统UI之变暗系统条
  7. tensorflow2.0 Dataset创建和使用
  8. 谁是ASML的最大股东?为何荷兰光刻巨头要听美国的话?
  9. SpringBoot 整合Redis报错:NoClassDefFoundError: redis/clients/util/SafeEncoder
  10. [COCI2017-2018#1] Plahte