Парсинг

M9
На сайте с 15.05.2014
Offline
79
892

Народ помогите а? что то мне мешает парсить такой запрос

мой код:


$html = new simple_html_dom();
$html = file_get_html("http://search.taotaosou.com/search/vsearch.do?url=http://img01.taotaosou.cn/size/image14/M0B/03/FD/wKgDvVW59P0IAAAAAADXNs9jcHMAAWypwGlfMgAANdO278_210x210.jpg&type=930&callback=json");
print_r($html);

но меня дразнить ошибка:


Warning: file_get_contents(http://search.taotaosou.com/search/vsearch.do?url=http://img01.taotaosou.cn/size/image14/M0B/03/FD/wKgDvVW59P0IAAAAAADXNs9jcHMAAWypwGlfMgAANdO278_210x210.jpg&type=930&callback=json) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in Z:\home\test1.ru\ on line 70

При этом отлично парсит такой запрос:

 include('simple_html_dom.php');

$html = new simple_html_dom();
$html = file_get_html("http://google.ru");
print_r($html);
Gerga
На сайте с 02.08.2015
Offline
94
#1
mega94:
HTTP*request*failed!*HTTP/1.1*403*Forbidden

тут все сказано. Пробуйте с помощью CURL.

M9
На сайте с 15.05.2014
Offline
79
#2
Gerga:
тут все сказано. Пробуйте с помощью CURL.

CURL конечно парсил но как преобразовать в dom ибо в json? ответь такой:


json({"similarList":[],"count":10,"proList":[{"title":"春秋低帮帆布鞋豹纹厚底松糕鞋一脚蹬懒人鞋韩版潮套脚女鞋休闲鞋","ttsid":3446067683,"picUrl":"http://img03.taobaocdn.com/bao/uploaded/i3/TB1ef2WHFXXXXaPaXXXXXXXXXXX_!!0-item_pic.jpg","promoPrice":"25.00","price":"98.00","webSite":"taobao","sales":0,"sourceId_gid":"520452871118_4604303048_3446067683","clickUrl":"http://item.taobao.com/item.htm?id\u003d520452871118\u0026spm\u003d2015.12313082.0.0","islower":1,"sourceId":"520452871118"},{"title":"2015春秋季女单鞋平底厚底圆头乐福豹纹帆布鞋浅口低帮休闲懒人鞋","ttsid":3348324077,"picUrl":"http://img02.taobaocdn.com/bao/uploaded/i2/TB1m3AXHpXXXXXdXpXXXXXXXXXX_!!0-item_pic.jpg","promoPrice":"29.80","price":"29.80","webSite":"taobao","sales":0,"sourceId_gid":"44705081708_4604303048_3348324077","clickUrl":"http://item.taobao.com/item.htm?id\u003d44705081708\u0026spm\u003d2015.12313082.0.0","islower":0,"sourceId":"44705081708"},{"title":"2015夏季新款欧洲站女鞋平底帆布豹纹乐福鞋休闲女士单鞋厚底鞋56","ttsid":3579003636,"picUrl":"http://img.alicdn.com/bao/uploaded/i1/TB1Sk.aHFXXXXXvXXXXXXXXXXXX_!!0-item_pic.jpg","promoPrice":"29.90","price":"29.90","webSite":"taobao","sourceId_gid":"520651705740_null_3579003636","clickUrl":"http://item.taobao.com/item.htm?id\u003d520651705740","islower":0,"sourceId":"520651705740"},{"title":"2015春秋新款韩版豹纹平底乐福鞋休闲鞋一脚蹬懒人鞋平跟单鞋","ttsid":3408730090,"picUrl":"http://img01.taobaocdn.com/bao/uploaded/i1/TB1gaYSHpXXXXcZXpXXXXXXXXXX_!!0-item_pic.jpg","promoPrice":"31.90","price":"77.80","webSite":"taobao","sales":0,"sourceId_gid":"44492462247_4604303048_3408730090","clickUrl":"http://item.taobao.com/item.htm?id\u003d44492462247\u0026spm\u003d2015.12313082.0.0","islower":0,"sourceId":"44492462247"},{"title":"2015新款夏季新品特价正品夏款韩版布浅口圆头平跟内增高黑色女鞋","ttsid":3410400410,"picUrl":"http://img03.taobaocdn.com/bao/uploaded/i3/TB1ef2WHFXXXXaPaXXXXXXXXXXX_!!0-item_pic.jpg","promoPrice":"40.00","price":"80.00","webSite":"taobao","sourceId_gid":"45602345742_4604303048_3410400410","clickUrl":"http://item.taobao.com/item.htm?id\u003d45602345742\u0026spm\u003d2015.12313082.0.0","islower":0,"sourceId":"45602345742"},{"title":"韩版新款潮马毛帆布乐福鞋帆布女鞋春秋单鞋女鞋","ttsid":3598995976,"picUrl":"http://img.alicdn.com/bao/uploaded/i1/TB1ZTONIpXXXXabXVXXXXXXXXXX_!!0-item_pic.jpg","promoPrice":"45.80","price":"45.80","webSite":"taobao","sourceId_gid":"521252368297_null_3598995976","clickUrl":"http://item.taobao.com/item.htm?id\u003d521252368297","islower":0,"sourceId":"521252368297"},{"title":"韩版新款潮马毛帆布乐福鞋帆布女鞋春秋单鞋女鞋","ttsid":3575881500,"picUrl":"http://img.alicdn.com/bao/uploaded/i1/TB1ZTONIpXXXXabXVXXXXXXXXXX_!!0-item_pic.jpg","promoPrice":"50.00","price":"50.00","webSite":"taobao","sourceId_gid":"520537108989_null_3575881500","clickUrl":"http://item.taobao.com/item.htm?id\u003d520537108989","islower":0,"sourceId":"520537108989"},{"title":"韩版新款潮马毛帆布乐福鞋帆布女鞋春秋单鞋女鞋","ttsid":3603062991,"picUrl":"http://img.alicdn.com/bao/uploaded/i1/TB1ZTONIpXXXXabXVXXXXXXXXXX_!!0-item_pic.jpg","promoPrice":"65.00","price":"65.00","webSite":"taobao","sourceId_gid":"521652176759_null_3603062991","clickUrl":"http://item.taobao.com/item.htm?id\u003d521652176759","islower":0,"sourceId":"521652176759"},{"title":"春秋新款真皮女鞋潮流行马毛豹纹休闲乐福鞋舒适女版平底单鞋女鞋","ttsid":3556236174,"picUrl":"http://img.alicdn.com/bao/uploaded/i1/TB1vjHCIXXXXXcdXFXXXXXXXXXX_!!0-item_pic.jpg","promoPrice":"78.00","price":"78.00","webSite":"taobao","sourceId_gid":"45308070908_null_3556236174","clickUrl":"http://item.taobao.com/item.htm?id\u003d45308070908","islower":0,"sourceId":"45308070908"},{"title":"韩版新款潮马毛帆布乐福鞋帆布女鞋春秋单鞋女鞋一件批发代","ttsid":3440802859,"picUrl":"http://img01.taobaocdn.com/bao/uploaded/i1/TB1ZTONIpXXXXabXVXXXXXXXXXX_!!0-item_pic.jpg","promoPrice":"88.00","price":"88.00","webSite":"taobao","sourceId_gid":"520305223905_4604303048_3440802859","clickUrl":"http://item.taobao.com/item.htm?id\u003d520305223905\u0026spm\u003d2015.12313082.0.0","islower":0,"sourceId":"520305223905"}],"leafCates":[{"name":"马丁靴","url":"http://www.taotaosou.com/category/1338.html"},{"name":"尖头鞋","url":"http://www.taotaosou.com/category/1373.html"},{"name":"懒人鞋","url":"http://www.taotaosou.com/category/795.html"},{"name":"粗跟鞋","url":"http://www.taotaosou.com/category/788.html"},{"name":"情侣鞋","url":"http://www.taotaosou.com/category/1210.html"},{"name":"纯色","url":"http://www.taotaosou.com/category/1209.html"},{"name":"中筒靴","url":"http://www.taotaosou.com/category/1341.html"},{"name":"豆豆鞋","url":"http://www.taotaosou.com/category/790.html"}]})

или есть библиотека какая нибудь как simple_html_dom на curl ?

PN
На сайте с 22.08.2012
Offline
103
#3

зачем что-то преобразовывать? Вы получили ответ JSON, используйте json_decode() и получите массив, а уж из него извлекайте что нужно.

Мой совет помог? Не скупись! Bitcoin 1Lseddet1o1B6odgXQHbGaWGwRkt1Db8Ef Ethereum 0x450f1a17461e25194B7F9226cDEe70173F39e1e1
M9
На сайте с 15.05.2014
Offline
79
#4
proksey-net:
зачем что-то преобразовывать? Вы получили ответ JSON, используйте json_decode() и получите массив, а уж из него извлекайте что нужно.

а как правильно json_decode() использовать


$ch = curl_init('http://search.taotaosou.com/search/vsearch.do?url=http://img01.taotaosou.cn/size/image14/M0B/03/FD/wKgDvVW59P0IAAAAAADXNs9jcHMAAWypwGlfMgAANdO278_210x210.jpg&type=930&callback=json');
curl_setopt($ch, CURLOPT_USERAGENT, 'IE20');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, '1');
$text = json_decode(curl_exec($ch));
curl_close($ch);
print_r($text);

что то php разучился=)

W
На сайте с 09.04.2013
Offline
46
#5
mega94:
а как правильно json_decode() использовать

Как-то так:


$ch = curl_init('http://search.taotaosou.com/search/vsearch.do?url=http://img01.taotaosou.cn/size/image14/M0B/03/FD/wKgDvVW59P0IAAAAAADXNs9jcHMAAWypwGlfMgAANdO278_210x210.jpg&type=930&callback=json');
curl_setopt($ch, CURLOPT_USERAGENT, 'IE20');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$page=curl_exec($ch);
curl_close($ch);
$json = substr($page,5,-1);
print_r(json_decode($json,true));
M9
На сайте с 15.05.2014
Offline
79
#6
webjey:
Как-то так:

$ch = curl_init('http://search.taotaosou.com/search/vsearch.do?url=http://img01.taotaosou.cn/size/image14/M0B/03/FD/wKgDvVW59P0IAAAAAADXNs9jcHMAAWypwGlfMgAANdO278_210x210.jpg&type=930&callback=json');
curl_setopt($ch, CURLOPT_USERAGENT, 'IE20');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$page=curl_exec($ch);
curl_close($ch);
$json = substr($page,5,-1);
print_r(json_decode($json,true));

спасибо добрый человек )

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий