【发布时间】:2015-04-11 06:07:12
【问题描述】:
我现在从泰卢固语网站抓取数据,当我从网站获取英文内容时,我可以毫无问题地获取它,但假设内容是泰卢固语(印度的泰米尔语)
它没有返回正确的字符串。
代码:
<?php
//
include "simple_html_dom.php";
// Get news from telugu site
$url = "http://www.123telugu.com/category/mnews";
$html = file_get_html($url);
$divs = $html->find('div.leading');
$result = array();
$status = FALSE;
$i = 0;
foreach ($divs as $d) {
$status = TRUE;
$title = $d->find('a', 0)->plaintext;
$result[$i]['Title'] = $title;
$link = $d->find('a', 0)->href;
$result[$i]['Link'] = $link;
$title = trim(mysql_real_escape_string($title)); // code for title
$html = file_get_html($link);
// code for image
$image = '';
foreach ($html->find('div.post-content') as $im) {
$image = $im->find('img', 0)->src; // code for image
}
$image = trim(str_replace('//', '', $image));
$result[$i]['Image'] = $image;
// code for content
$content = '';
foreach ($html->find('div.post-content p') as $co) {
$content.= $co->plaintext; // code for content
}
$result[$i]['Content'] = $content;
$i++;
}
echo json_encode(array('Status' => $status, 'Data' => $result));
【问题讨论】:
-
把你用来报废网页的代码放上去。
标签: php android mysql web-services web-scraping