本文整理汇总了PHP中phpQuery::newDocumentHtml方法的典型用法代码示例。如果您正苦于以下问题:PHP phpQuery::newDocumentHtml方法的具体用法?PHP phpQuery::newDocumentHtml怎么用?PHP phpQuery::newDocumentHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpQuery
的用法示例。
在下文中一共展示了phpQuery::newDocumentHtml方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _tryGetItools
private function _tryGetItools($url, $count = 3)
{
$result = Crawler::curl($url);
//$result = file_get_contents(Yii::app()->basePath . '/itools.html');
if ($result) {
phpQuery::newDocumentHtml($result);
$bestLis = pq('#daySelectCon ul.ios_app_list li');
$this->_itoolsSave($bestLis, 11);
$softLis = pq('.ios_box:eq(2)')->find('ul.ios_app_list li');
$this->_itoolsSave($softLis, 12);
return true;
} elseif ($count !== 0) {
$count--;
sleep(1);
return $this->_tryGetItools($url, $count);
}
return false;
}
示例2: getRows
public function getRows($pq)
{
$rows = $pq->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
$n = count($rows);
echo 'Jumlah propinsi: ' . $n . " \n";
$count = 0;
foreach ($rows as $value) {
$count++;
$row = pq($value);
$kolom_provinsi = $row->find('td:eq(1) > a');
$nama_provinsi = $kolom_provinsi->text();
$link_provinsi = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolom_provinsi->attr('href')) . '&perhal=1000';
echo sprintf("Memproses propinsi %d dari %d\n", $count, $n);
echo sprintf("Propinsi: %s Link: %s\n", $nama_provinsi, $link_provinsi);
$province = Province::model()->findByAttributes(array('name' => $nama_provinsi));
if (!$province instanceof Province) {
$province = new Province();
$province->name = $nama_provinsi;
if (!$province->save()) {
throw new CException('Cannot save province');
}
}
$countdistrict = 0;
$pqDist = phpQuery::newDocumentHtml($this->getContents($link_provinsi));
$rowsDist = $pqDist->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
$nDist = count($rowsDist);
$countDist = 0;
foreach ($rowsDist as $valueDist) {
$countDist++;
$rowDist = pq($valueDist);
switch ($rowDist->find('td:eq(2)')->text()) {
case 'Kota':
$tipeDist = 'kota';
break;
default:
case 'Kab.':
$tipeDist = 'kabupaten';
break;
}
$kolomDist = $rowDist->find('td:eq(3) > a');
$namaDist = $kolomDist->text();
$linkDist = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolomDist->attr('href')) . '&perhal=1000';
echo sprintf("Memproses distrik " . $province->name . " %d dari %d\n", $countDist, $nDist);
echo sprintf("Distrik: %s Link: %s\n", $namaDist, $linkDist);
$distrik = District::model()->findByAttributes(array('name' => $namaDist, 'province_id' => $province->id, 'type' => $tipeDist));
if (!$distrik instanceof District) {
$distrik = new District();
$distrik->name = $namaDist;
$distrik->type = $tipeDist;
$distrik->province_id = $province->id;
if (!$distrik->save()) {
throw new CException('Cannot save district');
}
}
$pqZone = phpQuery::newDocumentHtml($this->getContents($linkDist));
$rowsZone = $pqZone->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
$nZone = count($rowsZone);
$countZone = 0;
foreach ($rowsZone as $valueZone) {
$countZone++;
$rowZone = pq($valueZone);
$kolomZone = $rowZone->find('td:eq(4) > a');
$namaZone = $kolomZone->text();
$linkZone = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolomZone->attr('href')) . '&perhal=1000';
echo sprintf("Memproses zone %d dari %d\n", $countZone, $nZone);
echo sprintf("zone: %s Link: %s\n", $namaZone, $linkZone);
$new_zone = false;
$zone = Zone::model()->findByAttributes(array('name' => $namaZone, 'district_id' => $distrik->id));
if (!$zone instanceof Zone) {
$zone = new Zone();
$zone->name = $namaZone;
$zone->active = 1;
$zone->district_id = $distrik->id;
if (!$zone->save()) {
throw new CException('Cannot save Zone');
}
$new_zone = true;
}
echo 'sukses saving zone' . "\n";
$countArea = 0;
$pqArea = phpQuery::newDocumentHtml($this->getContents($linkZone));
$rowsArea = $pqArea->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
$nArea = count($rowsArea);
// Let's speed up things a bit
$trans = Yii::app()->db->beginTransaction();
foreach ($rowsArea as $valueArea) {
$countArea++;
$rowArea = pq($valueArea);
$kolomArea = $rowArea->find('td:eq(2) > a');
$kolomKodePos = $rowArea->find('td:eq(1)');
$namaArea = $kolomArea->text();
$kodePos = $kolomKodePos->text();
$linkKodePos = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolomArea->attr('href')) . '&perhal=1000';
$area = $new_zone ? null : Area::model()->findByAttributes(array('name' => $namaArea, 'zone_id' => $zone->id));
if (!$area instanceof Area) {
$area = new Area();
$area->name = $namaArea;
$area->postcode = $kodePos;
$area->zone_id = $zone->id;
if (!$area->save()) {
//.........这里部分代码省略.........