从外部数据库加载页面并对其进行处理

时间:2018-11-20 13:24:55

标签: javascript google-chrome google-chrome-extension

我正在尝试创建一个扩展程序,以收集许多站点上的数据,但是我对chrome扩展程序的结构有些迷惑。当我在后台页面上加载页面时,它永远不会停止加载。当我将它放在content.js中时,我用来处理页面中数据的回调函数没有时间处理该页面已被重新加载的情况。

$(document).ready(function() {
    //Charge la bonne adresse
        // $("#test").load("https://www.scripts.laportedubengale.be", {});
        var cont2 = $("iframe").contents().find('.product-details').html();
        setTimeout(function(){ 
        console.log('CONT 2 : '+cont2);
        // $("header").hide();
        console.log( "ready!" );
        var short_desc = $("iframe").contents().find('.more-list').html();
        var nom = $("iframe").contents().find('.page-title').html();
        var description = $("iframe").contents().find('#mainSpec .module-body .clearfix').html();
        var image_src = $("iframe").contents().find('.mz-image-stage img').attr('src');
        $("header").css('background-color', 'yellow');
        var cont = $("iframe").contents().find('.features').html();
        console.log('Description : '+description);
        console.log('Prix : '+prix);
        console.log('Short desc : '+short_desc);
        console.log("Window location");
        $("body").load("https://localhost/Solutions-web/Extracteur/Scripts/insertion_produit.php", {short_desc:short_desc, prix:prix, nom:nom, description:description, image_src:image_src});
    });

});

这是我的内容脚本。我在哪里加载要在数据库中加载的页面号。然后,当我获得该页面的数据时,我便清除了正文发送给治疗页面中的数据。

这是第一次加载时页面的代码。

<script src="https://www.scripts.laportedubengale.be/jquery.js"></script>
<div id="iframe" class="gogo">
</div>
<?php
	//fonction pour retourner les produits d'une catégorie
	include("includes/connect.php");
	$id_cat = '0';
	// $id_cat = $_POST['id_cat'];
	// $name_cat_wp = $_POST['name_cat_wp'];
	// $id_cat_wp = $_POST['id_cat_wp'];
	$req = $bdd->query("SELECT * FROM extracteur WHERE check_prod='0' and categorie='0' LIMIT 0,1");
	// $req = $bdd->query("SELECT * FROM extracteur WHERE categorie='" . $id_cat . "' ORDER BY id LIMIT 0,1");
	// $req2 = $bdd->query("INSERT INTO wp_terms(term_id, name, slug, term_group) VALUES('" . $id . "', '" . $name . "', '" . $slug . "', '0')");
	// echo 'Catégorie : '.$id_cat.'<br/>';
	$donnees = $req->fetch();
	echo $donnees['id_tech'];
	// ?>AAA
	
		<script>
		 // Script de traitement
		 // setTimeout(function(){
				window.location ='https://intouch.techdata.com/InTouch/MVC/Product/ProductDetails?productid=4325923&sessionid=1806135105065614B8FFB374B5A46FB95758B132E056300';
				// $("header").load("traitement.php", {});
			// },2000);
		</script>
	 <?php
?>
(I used a snippet because the code tag doesn't work for this code)

我在代码中有些迷惑,我不确定我是否正确解释了。 因此,内容脚本加载了另一个页面,该页面用window.location更改了页面,但是随后重新加载了内容脚本。因此,我什至没有时间保存数据。

有人可以更好地加载外部数据库给定的页面吗?

0 个答案:

没有答案