I'm playing around with an idea, and I'm stuck at this one part. I want to read an external HTML page and then extract the data held within two开发者_如何学Python <dd>
tags. I've been using file_get_contents
with good results, but I'm at a loss as to how to accomplish that last part. The two tags I want to extract the value from are always enclosed within a particular <div>
, was wondering if that might help?
In my mind it reads the entire html file into a string, then dumps all the data up until this one particular <div>
, and dumps all the data after the closing </div>
. Is that possible? I think this needs regex syntax which I've never used yet. So any tips, links, or examples would be great! I can provide more info as necessary.
Maybe this could help: http://simplehtmldom.sourceforge.net/
You are complicating way too much. Simply load the page content and then search for the proper regex (preg_match()
). This will do fine
preg_match('~<tag id="foobar">(?P<content>.*?)</endtag>~is', $input, $matches);
If you use HTQL COM to query the page, the query is: <dd>1:tx
精彩评论