如何使用PHP从我的网站提取/获取和显示数据(从其他电子商务网站)

I have seen many of the eCommerce portals which are showing the list of products from another bigger eCommerce websites from across the world.

The fetching is not a big problem i think, by using file_get_contents or CURL in php, But the question is,

Do they provide some api to allow others to fetch their data/product info?

Do we need to get their permissions to fetch data from their sites.

Are there some elegant and specific method/way to fetch data to show on our site (instead of CURL & file_get_contents)?

Some websites provide their API to access data. Some cost money, Some may be free. In any case , yes, you need permission.

But you can always scrape their sites without permission.

Here's some general guidelines on the subject.

  • You should check to see if they have a robot.txt file denying permission to spider some areas of the site.
  • Although there are copyright issues with reproducing content, search engines publish excerpts of site content all the time. Therefore to some extent, reproducing content is legally permissible.
  • APIs are sometimes available, but search engines scrape sites all the time without any sort of permission (except for perhaps the robot.text files).
  • Respect the site owner's wishes concerning their bandwidth. Poorly written robot code can wastefully tie up server resources.
  • If you can get permission, all the better.

I use cURL and the DomDocument class. I don't know what else you would want in terms of elegance.

  1. Write a crawler to get all the data you want from those websites.
  2. Use the APIs if provided.But usually it costs much.
  3. Create you own APIs using third-party software.