【发布时间】:2010-04-30 06:28:01
【问题描述】:
好的,伙计们.. 我有一个 HTML,我需要将其解析为一个 php 脚本,并在 abit 周围破坏数据。为了获得最佳解释,我将展示如何在 bash 脚本中使用 awk、grep、egrep 和 sed 通过一组糟糕透顶的管道来执行此操作。为清楚起见进行了评论。
curl -s http://myhost.net/mysite/ | \ # retr the document
awk '/\/\action/,/submit/' | \ # Extract only the form element
egrep -v "delete|submit" | \ # Remove the action lines
sed 's/^[ \t]*//;s/[ \t]*$//' | \ # Trim extra whitespaces etc.
sed -n -e ":a" -e "$ s/\n//gp;N;b a" | \ # Remove every line break
sed '{s|<br />|<br />\n|g}' | \ # Insert new line breaks after <br />
grep "onemyndseye@localhost" | \ # Get lines containing my local email
sed '{s/\[[^|]*\]//g}' | \ # Remove my email from the line
这些命令采用如下形式的元素:
<form action="/action" method="post">
<input type="checkbox" id="D1" name="D1" /><a href="http://www.linux.com/rss/feeds.php">
http://www.linux.com/rss/feeds.php
</a> [email:
onemyndseye@localhost (Default)
]<br />
<input type="checkbox" id="D2" name="D2" /><a href="http://www.ubuntu.com/rss.xml">
http://www.ubuntu.com/rss.xml
</a> [email:
onemyndseye@localhost (Default)
]<br />
<input type="submit" name="delete_submit" value="Delete Selected" />
并将其分解为完整的单行输入语句。准备插入另一种形式:
<input type="checkbox" id="D1" name="D1" /><a href="http://www.linux.com/rss/feeds.php">http://www.linux.com/rss/feeds.php</a> <br />
<input type="checkbox" id="D2" name="D2" /><a href="http://www.ubuntu.com/rss.xml">http://www.ubuntu.com/rss.xml</a> <br />
最大的问题是如何在 PHP 中实现这一点?我很喜欢使用 PHP 卷曲页面……但似乎我在过滤输出时迷失了方向。
提前致谢。 :)
【问题讨论】: