$html=file_get_contents("http://www.amazon.co.jp/s/fst=nb___mk_ja_JP=%E3%82%AB%E3%82%BF%E3%82%AB%E3%83%8A&url=node%3D466280&field-keywords=%E6%96%B0%E5%88%8A"); //sjis conversion $domDocument = new DOMDocument(); $domDocument->loadHTML ($html); $xmlString=$domDocument->saveXML(); $xmlObject=simplexml_load_string($xmlString); var_dump($xmlObject);
I tried a website other than Amazon and found a plastic surgery.
What is the difference?
As you can see in the comment in the question, if you try with the URL shown, you will get a perspective error.
There is a grammatical error in the HTML that Amazon returns.
I can't think of a way to get through something with these errors, so I just point out the cause.
The following error occurred in my environment (PHP 5.6.9-pl0-gentoo) (only the first part is long):
If you look at the XML in that part, the comment is incorrect because
-- appears between the comment
-->.This causes a perspective error.
--> in this XML source to pass.
-- restrictions (due to SGML balance) are relatively forgettable.)
Now that we know the code fragments that cause the error, we could easily get to the cause by launching an interactive shell with
php-a, executing one line at a time, and checking the variable contents with
var_dump() as appropriate.In fact, I understood the cause in that way.
In this example, a warning/error message is displayed in
$xmlObject=simplexml_load_string($xmlString); so you may notice that HTML is wrong.
It is usually a bad idea to parse human HTML data, so you should use the API.You may want to check the product from the search results, but you may be able to use the Product Advertising API.
© 2022 OneMinuteCode. All rights reserved.