cURL ที่ใช้ดึงหน้าเว็บอะครับ

เริ่มโดย sakang, 04 กุมภาพันธ์ 2011, 00:45:21

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

sakang

ดึงหน้ามา แล้วก็ใช้ฟังชั่นอื่นตัดส่วนเอาใช่รึเปล่าครับ แล้วมันต่างจากใช้  file_get_contents ยังไงหรอครับ

dragonmath

#1
ด้านประสิทธิภาพ
ความเร็วในการดึงต่างกันครับ curl จะดึงได้เร็วกว่าๆ
ด้านการใช้งาน
การใช้ curl เราสามารถ post, put ละก็ get.แต่ file_get_contents ทำได้แค่ get เพียงอย่างเดียว.
[direct=http://www.tewmath.com]กวดวิชา[/direct][direct=http://playgame.tewmath.com]เกมส์[/direct]
[direct=http://dragonmath.freevar.com/?p=354]สนใจโปรแกรม wpautocomment คลิกที่นี่[/direct]

dragonmath

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/path/to/form");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);

$data = array(
    'foo' => 'foo foo foo',
    'bar' => 'bar bar bar',
    'baz' => 'baz baz baz'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
ตัวอย่างการใช้งานๆ
[direct=http://www.tewmath.com]กวดวิชา[/direct][direct=http://playgame.tewmath.com]เกมส์[/direct]
[direct=http://dragonmath.freevar.com/?p=354]สนใจโปรแกรม wpautocomment คลิกที่นี่[/direct]

ball6847

curl กับ file_get_contents ดึงได้เหมือนกันไม่ต่าง

แต่ curl จะเปนทางออกที่ดีเสมอเวลาที่ file_get_contents ไม่เวิร์ค

ส่วนเรื่องการดึงข้อมูลออกมาจาก ผลลัพท์ที่ได้จาก curl หรือ file_get_contents
ใช้ regular expression หรือไม่ก็พวก substr , strpos
We use Ubuntu.

[direct=http://ng-seo.sourcelab.xyz/]AngularJS SEO Experimental[/direct]

kongpair

#4
file_get_contents  ได้ข้อมูลมาเป็น String  ใช้ Ram น้อยกว่า

Curl ได้มาเป็น Object ใช้ Ram มากกว่า


ในกรณีที่ข้อมูลเดียวกัน

Twenty-One

ยืนยันตาม dragonmath ว่า cURL  ทำงานได้ดีกว่าครับ เร็วกว่า

:wanwan017:
# บริการโฮสติ้งขั้นเทพ 24/7 เปิดให้บริการ web hosting มาแล้ว 14 ปี ลูกค้ากว่า 40,000 ราย ให้ความไว้วางใจ
# [direct=https://www.hostneverdie.com]hosting[/direct] คุณภาพสูง ดูแลระบบโดย system engineer ประสบการณ์สูง
# [direct=https://www.hostneverdie.com]host[/direct] เร็ง แรง ไม่มีล่ม ติดตั้ง cms ฟรี
# [direct=https://www.hostneverdie.com/vps-server]vps[/direct] ราคาถูก 50GB 999 บาท

[direct=https://www.hostneverdie.com][/direct]

ColdMoney

cURL เร็วกว่ามากครับ และทำ multi session ได้  :wanwan019:
[direct=https://www.jumnong.com]รับจำนอง[/direct] [direct=https://burapasup.com]รับซื้อบ้าน[/direct] [direct=https://kadsan.com]สินค้าราคาถูก[/direct] [direct=https://checkcheap.com]เปรียบเทียบราคา[/direct]

TG_Min

ใช้คำสั่ง curl แล้วหน้ามันว่างๆ ทั้งๆ ที่ php ก็เปิดใช้งานคำสั่งนี้ หมายความว่ายังไงครับ ต้องแก้ยังไง

code ที่ใช้ก็เหมือนด้านบน ตัวอย่าง

<?php
$ch 
curl_init();
curl_setopt($chCURLOPT_URL"feed");
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_POSTtrue);
curl_setopt($chCURLOPT_POSTFIELDS$data);
$output curl_exec($ch);
$info curl_getinfo($ch);
curl_close($ch);
echo 
$output;
?>



มันก็ได้กับ host อื่น แต่ host ตัวที่ใช้มันว่าง โล่ง ขาวสะอาดไม่ขึ้นไรเลย
[direct=https://www.kasetorganic.com/shop/]Shop[/direct] [direct=https://www.dek-d.com/member/profile/beautisora/blog]บล็อกของ Sora[/direct] [direct=https://krabi.vwander.com]เที่ยวกระบี่ไปได้ทุกวัน[/direct]


TG_Min

[direct=https://www.kasetorganic.com/shop/]Shop[/direct] [direct=https://www.dek-d.com/member/profile/beautisora/blog]บล็อกของ Sora[/direct] [direct=https://krabi.vwander.com]เที่ยวกระบี่ไปได้ทุกวัน[/direct]

TG_Min

ตอนนี้เจอปัญหาใหม่ เข้าใจว่าปัญหาเดิมคือมันไม่ยอมให้ดึง url จากภายนอก (เลยแสดงค่าว่างไว้) ยกเว้นภายใน domain มันเอง
ลองใส่ url ใน domain มันเองก็ดึงได้ แต่ใส่ url ภายนอกมันไม่ทำงาน ต้องแก้ยังไงดีครับ

เซ็งกะ host นี้จริงๆ
[direct=https://www.kasetorganic.com/shop/]Shop[/direct] [direct=https://www.dek-d.com/member/profile/beautisora/blog]บล็อกของ Sora[/direct] [direct=https://krabi.vwander.com]เที่ยวกระบี่ไปได้ทุกวัน[/direct]

vii

อ้างถึงจาก: TG_Min ใน 19 กรกฎาคม 2011, 11:48:35
ตอนนี้เจอปัญหาใหม่ เข้าใจว่าปัญหาเดิมคือมันไม่ยอมให้ดึง url จากภายนอก (เลยแสดงค่าว่างไว้) ยกเว้นภายใน domain มันเอง
ลองใส่ url ใน domain มันเองก็ดึงได้ แต่ใส่ url ภายนอกมันไม่ทำงาน ต้องแก้ยังไงดีครับ

เซ็งกะ host นี้จริงๆ
host block ไว้รึเปล่าครับ ลองดึงจาก google.com ดู ปกติจะต้องดึงได้
ถ้าดึงจาก url ตัวเองได้แต่ url คนอื่นไม่ได้ก็โดนบล็อกแล้วครับ ที่ host นะ

TG_Min

โดนล๊อคจริงๆ อ่ะครับ ทดลองกับหลายๆ คำสั่งแล้ว
ในตัวเองได้ แต่ดึงจาก url นอกไม่ได้เลย

ให้ admin แก้ไขแล้วเค้าบอกกำลังติดต่อกับ admin ต่างประเทศ
ก็รอต่อไป เฮ่อ ขอบคุณมากมายครับทุกท่าน
[direct=https://www.kasetorganic.com/shop/]Shop[/direct] [direct=https://www.dek-d.com/member/profile/beautisora/blog]บล็อกของ Sora[/direct] [direct=https://krabi.vwander.com]เที่ยวกระบี่ไปได้ทุกวัน[/direct]

loveme2


bananaoxy

[direct=https://mining.in.th/]>ตลาดชื้อขายอุปกรณ์ขุด bitcoin [/direct]

dreamer

ตามความเข้าใจของผมนะ

file_get_content ก็เหมือนอ่านไฟล์ที่อยู่ที่ไหนก็ได้ เครื่องเดียวกันหรือเครื่องอื่นก็ได้

cURL จำลอง browser มาเลย

flash

ที่เคยลองใช้ curl จะกิน CPU 100% เป็นช่วงๆ  ครับ  ไม่รู้จะแก้ยังไงดี
[direct=http://www.mclshop.com/]ครีมหมอจุฬา[/direct] ผ่าน อย. อยากหน้าใส ไร้รอยด่างดำ ครีมหมอจุฬาซื้อที่ไหน หาไม่ยากเลย แต่ระวังของปลอมนะ ของเราเป็น ครีมหมอจุฬาของแท้ 100% มาดูสินค้าก่อนได้


Tee++;

ลองหันมาดู YQL บ้างมั้ยครับ ทำ Selector แบบไม่เปลือง SERVER เราเอง อาทิเช่นผมต้องการดึงเว็บ ก็

select * from html where url="http://www.jquerytips.com" and xpath='//div[@id="container"]'

ซึ่งก็คือ

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.jquerytips.com%22%20&diagnostics=true

ถ้าผมต้องการเขียน Regular ก็
select * from regex where expression = "(.*)" and text = "The quick brown fox leaps over the lazy dog";

ต้องการโพสต์ฟอร์ม
select * from htmlpost where
url='http://isithackday.com/hacks/htmlpost/index.php'
and postdata="foo=foo&bar=bar" and xpath="//p"


ใช้  CSS Selector
select * from data.html.cssselect where url="www.jquerytips.com" and css=".widget_entries"

นอกจากนี้ยังทำอะไรได้อีกหลายร้อยแบบ อาทิเช่น ต่อ Social Network API, ดึง Multi Feed 

แล้วก็นอกจาก Return เป็น  XML ยังสามารถ Return  เป็น JSON ได้อีกด้วย

แล้วก็ Rate Limit สูงมาก 100,000/day 1000/ip/day  ต่อ access key (จริงๆ แล้วขอมากี่ key ก็ได้ ให้เยอะตาม สไตล์ API Yahoo ครับ)

ลองเล่นดูเองก็ได้ครับ
http://developer.yahoo.com/yql/console/
[direct=http://laravel.in.th]Laravel in Thai[/direct]
[direct=http://jquerytips.com]jQueryTips by Tee++;[/direct]
[direct=https://www.facebook.com/jQueryTips]jQueryTips Page[/direct]
[direct=https://www.facebook.com/Laravel.in.th]Laravel in Thai Page[/direct]
[direct=https://twitter.com/Teepluss]Teepluss's Twitter[/direct]