PHP: I want to capture webpage-specific data. I want to capture webpage: the specific data of PM2.5 in the form of www.pm2d5.comCityxg_wangjiao.html webpage. Is there any efficient method? Thank you .. ------ Solution ------------------ I am a stupid method, but my regular expression is too bad. PHPcode $ html is the www. pm2d5. c you want to crawl webpage-specific data.
I want to capture the specific data of the table gripm2.5on the webpage: http://www.pm2d5.com/city/xg_wangjiao.html,
Is there any efficient way? Thank you ..
------ Solution --------------------
I am stupid, but my regular expression is really bad.
PHP code
// $ Html is the content of www.pm2d5.com/city/xg_wangjiao.html "/[\ S \ S] +? <\/Td>/I "; preg_match_all ($ pattern, $ html, $ tdTag); // var_dump ($ tdTag ); // HTML tag $ deleteStrHeader = 'in the matching result to be eliminated''; $ DeleteStrFooter =''; $ Pmvalue = array (); foreach ($ tdTag [0] as $ key => $ value) {// if ($ key + 1) % 6 ===0) when traversing the column of pm2.5 {// remove the header and tail HTML tag $ noHeaderStr = str_replace ($ deleteStrHeader, '', $ value); $ cleanStr = str_replace ($ deleteStrFooter,'', $ noHeaderStr); // Convert to float type $ pmvalue [] = (float) trim ($ cleanStr) ;}} var_dump ($ pmvalue );