Skip to content
Advertisement

Website Scraping with PHP,Curl and MySQL Database

sorry am having bit of trouble here storing scraped content into MYSQL database.

So what am trying to do is save the Module Code and Module Title from this site [http://www.ucc.ie/modules/descriptions/page014.html][1] into MYSQL database. Am able to get content from the site alright but I just cant seems to be able to save scraped content into database.I keep getting the error “Query was empty” while the query is not.

Been spending sometime doing this and can’t seems to get around it. Any help in solving this problem would be appreciated.

JavaScript

And below is the MYSQL table I created to store the content

JavaScript

Any help in figuring out why my content is not saving to the database would be appreciated.

Advertisement

Answer

Your content variables are indeed empty at the point at which you construct the sql query- they were unset above.

JavaScript

I think you probably want $value’s nodeValue content from each of your $content as $value strings to be placed in that mysql query (you can access the textual content of nodes using $value->nodeValue).

For example, if you want the textual content of a node such as this P node from your example, which looks like this when you print_r the node:

JavaScript

you can see that there are two values in that node that might be interesting to you – textContent and nodeValue.

You can access these from your code by doing this:

JavaScript

This will print out the text from all your P nodes.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement