Back to Question Center
0

Semalt: Mehato e 3 ho PHP Web Page Sekhahla

1 answers:

mokhoa oa ho tlosa dintlha ho tswa ho websaeteng kapa blog. Boitsebiso bona bo sebelisetsoa ho beha meta tags, litlhaloso tsa meta, li-keywords le li-link ho site, ho ntlafatsa ts'ebetso ea eona ka ho feletseng liphellong tsa motei ea ho batla.

Mekhoa e 'meli e meholo e sebelisetsoa ho hlakola dintlha:

  • Document parsing - E kenyeletsa tokomane ea XML kapa HTML e fetisetsoang DOM (Document Object Model ) lifaele. PHP e re fa ka katleho e kholo ea DOM.
  • Mantsoe a kamehla - Ke mokhoa oa ho hlakola dintlha ho tswa ho ditokomane tsa marang-rang ka mokhoa o tloaelehileng oa lipolelo.

Taba ka ditshwantsho tsa marang-rang ea marang-rang a marang-rang a amana le litokelo tsa lona tsa molao hobane ha u na tumello ea ho sebelisa data ena. Empa ka PHP, o ka hlakola data habonolo ntle le mathata a amanang le litokomane kapa boleng bo tlaase. Joaloka moqapi oa PHP, u ka hloka data ho tsoa mawebsaeteng a fapaneng bakeng sa merero ea coding. Mona re hlalositse kamoo re ka fumanang data ho liwebsaete tse ling ka katleho, empa pele ho moo, o lokela ho hopola hore qetellong o tla fumana lifaele tsa index.php kapa scrape.js.

Mehato ea 1: Etsa foromo ea ho kenya Websaeteng ea URL:

Ntlha ea pele, o lokela ho etsa foromo ho index.php ka ho tobetsa Letšoao la ho kenya le ho kenya URL ea marang-rang ea ho fumana data.



kenya URL ea marang-rang bakeng sa ditshwantsho tsa marang-rang

)



Mehato2: Etsa Mosebetsi oa PHP ho fumana Website Data:

Mohato oa bobeli ke ho bopa PHP ts'ebetso ea sefapane ho file ea scrape.php kaha e tla thusa ho fumana data le ho sebelisa laebrari ea URL. E tla boela e lumelle hore u hokahane le ho buisana le lisebelisoa tse fapaneng le li-protocol ntle le taba leha e le efe..

mosebetsi scrapeSiteData ($ website_url) {

haeba (! Function_exists ('curl_init')) {

shoa ('cURL ha e kene. ');

}

$ curl = curl_init

;

curl_setopt ($ curl, CURLOPT_URL, $ website_url);

curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 'nete);

$ output = curl_exec ($ curl);

curl_close ($ curl);

khutlisa chelete e tsoang ho $;

}

Mona, re ka bona hore na PHP cURL e kentsoe hantle kapa che. Li-cURL tse tharo tse kholo li lokela ho sebelisoa sebakeng sa mosebetsi le curl_init

e tla thusa ho qalisa lenaneo, curl_exec

e tla e phetha le curl_close

e tla thusa ho koala kgokahano. Liphetoho tse kang CURLOPT_URL li sebelisetsoa ho beha URL ea marang-rang eo re e hlokang ho e qeta. Ea bobeli CURLOPT_RETURNTRANSFER e tla thusa ho boloka maqephe a qhetsoeng ka fomoleng e fapaneng ho e-na le foromo ea oona e sa fetoheng, e qetellang e bonts'a leqephe lohle la websaete.

Mehato ea 3: Litsebiso tse hlakileng tsa Scrape ho Website:

Ke nako ea ho sebetsana le lits'ebeletso tsa file ea hau ea PHP le ho hlahisa karolo e itseng ea leqephe la hau la web. Haeba u sa batle boitsebiso bohle ho URL e itseng, u lokela ho fetola sebelisa mefuta ea CURLOPT_RETURNTRANSFER le ho totobatsa likarolo tseo u batlang ho li qhaqha.

haeba (setset ($ _ POST ['submit'])) {

$ html = scrapeWebsiteData ($ _ POST ['website_url']);

$ start_point = strpos ($ html, 'Latest Posts');

$ fin_point = strpos ($ html, '', $ start_point);

$ bolelele = $ qet_point- $ start_point;

$ html = substr ($ html, $ start_point, $ bolelele);

echo $ html;

}

Re u eletsa hore u hlaolele tsebo ea motheo ea PHP le Mantsoe a Kamehla pele u sebelisa leha e le efe ea melao ena kapa u hlahise blog kapa marang-rang a itseng bakeng sa merero ea botho.

December 8, 2017
Semalt: Mehato e 3 ho PHP Web Page Sekhahla
Reply