ไม่ไหวแล้วครับ ขอเคลียร์งมมาข้ามปีแล้วครับ ขอความช่วยเหลือที

เริ่มโดย $100perday, 02 มกราคม 2013, 11:55:44

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

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

$100perday

 :wanwan017: อุ๊ยย!! ตั้งหัวข้อซะแซ่ปเชียว
ผมค้นหาข้อมูลของการใช้ CURL และ File_get_content หลายสำนักแล้วครับ
ไม่ได้และไม่เข้าใจสักที ขอท่านเทพ ฯ ทีนี้ โปรดเมตตาผมทีเถอะครับ
ขอ code ตัวอย่างที่สามารถทำให้ผมเอาไปต่อยอด หรือใช้งานได้พอเห็นผลสักหน่อย
ขอสัญญาว่า จะนำสิ่งที่ได้ไปนำไปพัฒนาและกลับมาพัฒนาบ้านของเราแน่นอน
รบกวนทีนะครับ

ความต้องการ
จากเว็บ http://news.mthai.com/general-news/210228.html
(ขออนุญาตนำมาจาก mthai.com นะคราบบ)

ผมต้องการเขียน cURL หรือ file_get_content
เพื่อดึง
1. หัวข้อ = เกาะติด 7 วันอันตราย ปีใหม่ 2556
2. รูปภาพ = http://news.mthai.com/wp-content/uploads/2012/12/1132.jpg
3. เนื้อหา

เพียง 3 อย่างครับ เก็บลง ตารางในฐานข้อมูล เช่น
Table = news
3 ฟิลด์ตามลำดับคือ
1. หัวข้อ = topic
2. เนื้อหา  = message และ
3. รูปข่าว = photo

เขียน code ยังไงครับ

ขอบคุณล่วงหน้าครับ  :wanwan017:
สวัสดีปีใหม่ 2556 จร้า
เหนื่อย..

xvlnw.com

[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

amjoey

เอาโค้ดนี้ไปใช้ดู  ช่วยๆกันครับ  :wanwan020:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
    $getpage = get_content("http://news.mthai.com/general-news/210228.html");
    preg_match("/<div class=\"entry-title\">([^`]*?)<\/div>/", $getpage, $topic); //
    echo $topic[1];
   
    function get_content($URL) {
         $ch = curl_init();
         $timeout = 0; // set to zero for no timeout
         $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
         curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
         curl_setopt ($ch, CURLOPT_URL, $URL);
         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
          $String = curl_exec($ch);
          curl_close($ch);
           return $String;
}
?>
ทำงานริมทะเล ด้วยหัวใจที่มั่นคง
[direct=http://www.veesa.com]รับทำเว็บไซต์[/direct]

kowit2

Be patient because patience looks natural.
ผลงานการทำเนื้อหา บทความ ที่มีคุณภาพในความเป็นจริงครับ

[direct=https://www.1belief.com/article/free-email-business/]ฟรีอีเมล ดีจริงหรือ ?[/direct]: ฟรีอีเมล ที่ให้ใช้งานทั่วไป เหมาะกับธุรกิจของคุณหรือไม่ หรือว่าถึงเวลาแล้วที่ต้องเปลี่ยนมาใช้ Email แบบเสียเงิน
[direct=https://www.1belief.com/article/virus-computer/Open link]ไวรัสคอมพิวเตอร์ รู้ไว้ป้องกันได้[/direct]: ไวรัสคอม ป้องกันได้ หากลองศึกษาวิธีการใช้งานที่ถูกต้อง และอย่าลืมติดตั้งโปรแกรมสแกนไวรัสด้วยนะ
[direct=https://www.yorushop.com/]yorushop[/direct]


$100perday

อ้างถึงจาก: xvlnw.com ใน 02 มกราคม 2013, 12:33:07
http://simplehtmldom.sourceforge.net/

** ขอบคุณมากครับ **
จัดให้เลย +1  :wanwan017:

อ้างถึงจาก: amjoey ใน 02 มกราคม 2013, 13:29:00
เอาโค้ดนี้ไปใช้ดู  ช่วยๆกันครับ  :wanwan020:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
    $getpage = get_content("http://news.mthai.com/general-news/210228.html");
    preg_match("/<div class=\"entry-title\">([^`]*?)<\/div>/", $getpage, $topic); //
    echo $topic[1];
   
    function get_content($URL) {
         $ch = curl_init();
         $timeout = 0; // set to zero for no timeout
         $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
         curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
         curl_setopt ($ch, CURLOPT_URL, $URL);
         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
          $String = curl_exec($ch);
          curl_close($ch);
           return $String;
}
?>

เดี๋ยวลองทดสอบและมารายงานผลให้ทราบนะครับ
ขอบคุณมากเลยครับ น้ำใจงาม จัด+1 ไป จร้า  :wanwan011: :wanwan017:
เหนื่อย..

$100perday

เหนื่อย..

idesigns

มาดูเคล็ดลับน่ารู้ที่

[direct=https://movie24freehd.com/]movie24freehd.com[/direct]
[direct=https://movies2freehd.com/]movies2freehd.com[/direct]
[direct=https://www.tamsabuy.net/]tamsabuy.net[/direct]
[direct=https://movie2hdfree.com/]movie2hdfree.com[/direct]
[direct=https://imoviehdfree.com/]imoviehdfree.com[/direct]


$100perday

อ้างถึงจาก: princmeen ใน 02 มกราคม 2013, 13:55:22
อันนี้ดูยัง file_get_contents
http://www.php.net/manual/en/function.file-get-contents.php

ผมทำตามตัวอย่างที่ให้มาอ่ะครับ

มันขึ้น error อย่างนี้ครับ

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/xxx/domains/xxx.com/public_html/test2.php on line 14

Warning: file_get_contents(http://news.mthai.com/general-news/210228.html) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/xxx/domains/xxx.com/public_html/test2.php on line 14

ไฟล์ test2.php ครับ

<?php
// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://news.mthai.com/general-news/210228.html', false, $context);
?>
เหนื่อย..

$100perday

อ้างถึงจาก: amjoey ใน 02 มกราคม 2013, 13:29:00
เอาโค้ดนี้ไปใช้ดู  ช่วยๆกันครับ  :wanwan020:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
    $getpage = get_content("http://news.mthai.com/general-news/210228.html");
    preg_match("/<div class=\"entry-title\">([^`]*?)<\/div>/", $getpage, $topic); //
    echo $topic[1];
   
    function get_content($URL) {
         $ch = curl_init();
         $timeout = 0; // set to zero for no timeout
         $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
         curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
         curl_setopt ($ch, CURLOPT_URL, $URL);
         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
          $String = curl_exec($ch);
          curl_close($ch);
           return $String;
}
?>

สุดยอดมากเลยครับ
ดึงหัวข้อออกมาได้

ถามนิสสสนึงนะครับ
ได้เฉพาะ mthai หรือเปล่าครับ
พอดีลองเว็บอื่นด้วย แต่ไม่แสดงผลอารายขึ้นมาเลย

ขอบคุณครับ  :wanwan017:
เหนื่อย..

adidog

ลองไปหาใน google เรื่อง
DOMDocument
DOMXPath

ดูครับ ไม่ยาก ถ้าแจกแล้วเทพๆจะถล่มมั๊ยเนี่ย  :P :P :P
Certain Dri [direct=http://www.ishiclub.com/]Certain Dri[/direct]
คุณแม่มือใหม่ [direct=http://www.mamyget.com/]คุณแม่มือใหม่[/direct]

amjoey

อ้างถึงจาก: $100perday ใน 02 มกราคม 2013, 14:02:03
อ้างถึงจาก: amjoey ใน 02 มกราคม 2013, 13:29:00
เอาโค้ดนี้ไปใช้ดู  ช่วยๆกันครับ  :wanwan020:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
    $getpage = get_content("http://news.mthai.com/general-news/210228.html");
    preg_match("/<div class=\"entry-title\">([^`]*?)<\/div>/", $getpage, $topic); //
    echo $topic[1];
   
    function get_content($URL) {
         $ch = curl_init();
         $timeout = 0; // set to zero for no timeout
         $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
         curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
         curl_setopt ($ch, CURLOPT_URL, $URL);
         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
          $String = curl_exec($ch);
          curl_close($ch);
           return $String;
}
?>

สุดยอดมากเลยครับ
ดึงหัวข้อออกมาได้

ถามนิสสสนึงนะครับ
ได้เฉพาะ mthai หรือเปล่าครับ
พอดีลองเว็บอื่นด้วย แต่ไม่แสดงผลอารายขึ้นมาเลย

ขอบคุณครับ  :wanwan017:

ได้ทุกเว็บครับ แต่ก็ต้องเปลี่ยนบรรทัดนี้นะครับ
preg_match("/<div class=\"entry-title\">([^`]*?)<\/div>/", $getpage, $topic);
ตามหน้าเว็บที่คุณจะดึงข้อมูล ว่าอยู่ใน tag และ class อะไร
ทำงานริมทะเล ด้วยหัวใจที่มั่นคง
[direct=http://www.veesa.com]รับทำเว็บไซต์[/direct]

$100perday

เหนื่อย..