如何使用正则表达式从网页中提取数据?

发布于 2024-07-18 14:23:04 字数 479 浏览 6 评论 0原文

我正在编写一个curl脚本来收集有关一些性犯罪者的信息,我开发了一个脚本来获取如下所示的链接:

http://criminaljustice.state.ny.us/cgi/internet/nsor/...< /a> (截取的 URL)

现在,当我们进入此链接时,我希望将此页面上的所有字段下的信息(例如罪犯 ID:、姓氏等)获取到我自己的变量中。 我在正则表达式方面很弱,这就是我来这里的原因。 或者还有别的办法吗?

有人可以帮我做到这一点吗?

I am writing a curl script for collecting information about some sex offenders, i have developed the script that is picking up links like given below:

http://criminaljustice.state.ny.us/cgi/internet/nsor/... (snipped URL)

Now when we go on this link I want to get information under all the fields on this page like Offender Id:, last name etc. into my own variables. I am very weak in regex that is why I am here. Or is there another way?

Can anybody help me in doing that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

太阳公公是暖光 2024-07-25 14:23:04

phpQuery 非常适合 PHP 中的屏幕抓取。 它允许您使用与 jQuery 相同的方法访问 DOM。

phpQuery is very nice for screen-scraping in PHP. It lets you access the DOM using the same methods jQuery has.

有深☉意 2024-07-25 14:23:04

我倾向于同意之前的帖子,认为正则表达式不是完成这项工作的正确工具。 如果你只是想要一个快速而肮脏的表达,这里是:

Offender Id:.*
.*&nbsp;[0-9]*

注意:
您必须在此表达式中包含换行符。 另请注意,这是非常脆弱的,因为如果您正在解析的源发生很大变化,它就会崩溃。

I tend to agree with the previous poster about RegEx not being the right tool for the job. If you just want a quick and dirty expression, here goes:

Offender Id:.*
.*&nbsp;[0-9]*

NOTE:
You must include the newline in this expression. Also note that this is very fragile as it will break if the source that your are parsing changes much at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文