0
我从网页刮某些URL一些奇怪的字符,并在网页上的显示精细,但是当我插入到数据库它插入一些奇怪这样刮板插入数据库
http://westseattleblog.com/event/west-seattle-church-listings/?instance_id=567059
我的代码
网址foreach($html->find('div[class=ai1ec-btn-group ai1ec-actions] a') as $element)
{
$url= $element->href;
$url1=mysql_real_escape_string($url);
$sql="insert into catlink(catlink) values('$url1')";
//echo $sql."<br>";
$query=mysql_query($sql);
//newpage
}
而当我开始从数据库中提取URL并逐一报废时,它什么都不显示。
我的代码
$sql1="select * from links limit 10";
$query1=mysql_query($sql1);
while($res=mysql_fetch_assoc($query1)){
$url=$res['url'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
// curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$page = curl_exec($ch);
curl_close($ch);
$dom = new simple_html_dom();
$html = $dom->load($page);
foreach($html->find("div") as $a){
echo $a->innertext;
}
//$separator = ' - ';
}
你的意思是说,你从查询到数据库什么都没有得到?关于乱码的内容,应该没问题。检查[这篇文章](http://stackoverflow.com/questions/7867204/how-should-be-kept-as-html-tags-in-database)。 –
Base64将URL编码为安全的Base64字符串,然后将其保存到数据库中。当Base64解码数据库中保存的字符串时,您可以轻松找回原始URL。请参阅http://stackoverflow.com/questions/13109588/base64-encoding-in-java –