Get values from php page
I've made a database,and for each row I've created a new php page and saved some values in the DB table.
Now, I want to insert the values from the PHP page that I've forgot to insert in the DB.
I only have 3 values. I know for each row the PHP page (url) from where I need to grab the values.
The values show up in the php page like this
<table>
<tr>
<td>
Column1
</td>
<td>
Value-c1
</td>
</tr>
<tr>
<td>
Column2
</td&开发者_运维问答gt;
<td>
Value-c2
</td>
</tr>
<tr>
<td>
Column3
</td>
<td>
Value-c3
</td>
</tr>
</table>
The page containg this table has other content too. I just need to take Value-c1 and insert it into Column1 in the MySQL table.
How can I get the content of the PHP page (having the URL) and also get the specific values that I want.
EDIT:
I have multiple static PHP pages (like 100) and I want to make a PHP script that will go through all the pages (I know their urls) and get from each page the values from the table and insert them into a DB.
Is that clear now? :D
What you need is called sreen (or web) scraping. See http://en.wikipedia.org/wiki/Web_scraping for details.
Take a look at
- How do you parse and process HTML/XML in PHP?
- html scraping and css queries
- http://www.bradino.com/php/screen-scraping/ - this a simple text parser (uses strpos®exp). Its recommended to avoid these as they are pretty hard to maintain, but it may be easier in your specific case(as you already have the files, and its unlikely you have different formats for them)
for more answers
The Easiest would probaly be to use Regex to get all the tr blocks from the page. You can then loop all the rows and run another Regex pattern to get the Column1 and the Value value.
精彩评论