天翼查号接口调用

49 篇文章 0 订阅
#!/usr/bin/python

import os


fh = open("code.txt", "r")

print "start crawling ....";
for line in fh:
    line = line.strip()
    print line
    os.system("php worker_tianyi.php %d &" % int(line))

fh.close()
print "crawling started ...";


http://open.189.cn/index.php?m=api&c=index&a=show&id=418

public function fetch_api_data($region, $word) {
		$page = 1;
		$form = array();
		$form['app_id'] = '****';
		$form['access_token'] = '*****';
		while(1) {
			$reqxml = '
<?xml version="1.0" encoding="UTF-8"?>
<reqXML version="1.0">
  <appKey>****</appKey>
  <apiName>cominfo</apiName>
  <apiMethod>getChaHaoInfo</apiMethod> 
  <timestamp>' . date('Y-m-d H:i:s') . '</timestamp>
  <params>
      <param name="region" value="' . $region . '"  />
      <param name="content" value="' . $word . '"  />
<param name="Page" value="' . $page . '"  />
<param name="PageSize" value="10"  />
<param name="deviceid" value="18930823591"  />
</params>
</reqXML>';
			 $form['reqXml'] = $reqxml;
			 
			 $query = http_build_query($form);
			 $result = $this->url->get_file('http://api.189.cn/besttone/getChaHaoInfo?' . $query);
			 if($result) {
			 	$result = $this->parse_xml($result);
			 	if(!$result) {
			 		return;
			 	}
			 }
			 sleep(10);
			
			 $page ++;
		}
		
	}
	
	public function parse_xml($result) {
	
		$xml = simplexml_load_string($result);
		$xml = $xml->ResultContent;
		
		$has_more = false;
		foreach($xml[0] as $ContentTags) {
			$has_more = true;
			$tag = $ContentTags->ContentTag[1]->propertyValue;
			$number = $ContentTags->ContentTag[3]->propertyValue;
			$this->add_data($number, $tag);
		}
		return $has_more;
	}
	


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值