用PHP自动搜索*数据库[关闭]

用PHP自动搜索*数据库[关闭]

问题描述:

I'm wondering if this is possible... In Ontario when a vehicle is transferred from one owner to another it needs to undergo an emissions test. The Ontario Government allows you search your car's history based on VIN, here: http://www.driveclean.ene.gov.on.ca/ONPublicWeb/pages/vir/vehSearch.jsf?LOCALE=en_CA

Is there a way for me to build a query in PHP that checks that database and returns the date it was tested? I'm new to this.

Thanks in advance!

我想知道这是否可行......在安大略省,当车辆从一个车主转移到另一个车主时 需要进行排放测试。 安大略省*允许您根据VIN搜索您的汽车历史,在这里: http://www.driveclean.ene.gov.on.ca/ONPublicWeb/pages/vir/vehSearch.jsf?LOCALE=en_CA p> 我有没有办法在PHP中构建一个查询该数据库并返回测试日期的查询? 我是新手。 p>

提前致谢! p> div>

Yes, look at using PHP cURL: http://php.net/manual/en/book.curl.php Your webserver or host's PHP configuration will need to be setup with cURL enabled, you can check phpinfo() to verify.

cURL will allow you to perform POST/GET and even SSL requests to the form's submission page http://www.driveclean.ene.gov.on.ca//ONPublicWeb/pages/vir/vehSearch.jsf. with a POST parameter of virSearchForm:VINId = vinnumber, virSearchForm:searchButtonId = search, and virSearchForm_SUBMIT = 1

Then you will need to parse out the response for the information you are looking for.

The biggest issue with this method is as they update their site, you will need to update your script as well.

Without testing, if they utilize a form of CSRF it can not be accomplished, as most techniques require a session state to generate a random number on each page view to authenticate from the form submission page with the processing page. However they do have a hidden form field javax.faces.ViewState that appears to be a CSRF token.

You can also check with their customer support to see if they have a formal web api that will allow you to send requests via http, similar to Google's API examples.

If the site provides an API, you may be able to add URL Query String items (e.g., &vin=123456789) and then scrape the resulting display page for the information you want.

If the site doesn't provide an API, but makes you fill out a form, I believe that there are various tools for generating inputs to a page, and then scraping information off the returned page. wget might do this (I'm not familiar enough with it to tell you for sure), and Selenium can do this (I believe it has a PHP language interface). I take it you want a completely "hands off" automated approach. How you do it will depend on whether this is a one-off or occasional job, or a production system, and whether you need to run it from a web site or from a PC.

Hopefully, the above information will be enough to get you looking in the right place. Keep in mind that the government site probably won't mind you doing this once in a while, but could get testy if you place a heavy load on their server. Check to see if they have any Terms and Conditions limiting or prohibiting what you want to do.