Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> [php][curl] Liczba stron w Yahoo
djgarsi
post 30.09.2010, 08:25:12
Post #1





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Witajcie. Interesuje mnie uzyskanie liczby stron zindeksowanych w Yahoo!.
Znalazłem jakiś kod udostępniany przez Yahoo jednak nie wiem jak go wykorzystać.
Jest on tu: http://developer.yahoo.com/php/samples/req...uestCURLGET.txt
Proszę o pomoc.


--------------------
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 08:35:25
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Kod co podales zwraca ci xml z wynikami wyszukiwania danej frazy.
Wystarczy sparsować ten xml i wyciągnąc liczbę wyników z argumentu o nazwie "totalResultsAvailable"


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
djgarsi
post 30.09.2010, 09:13:22
Post #3





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Ok. Tylko że mi na serwerze file_get_contents i simplexml_load nie działa.sad.gif


--------------------
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 09:24:17
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




A nie możesz włączyc opcji allow_url_fopen ? Wowczas ci zadziala

edit:
a po co ci w ogóle file_get_contents()? Przecież skrypt co podałes obchodzi się bez tego. Sam podales skrypt a teraz nie chcesz z niego skorzystac? Leon, why?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
djgarsi
post 30.09.2010, 09:35:42
Post #5





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Z file_get_contents to mój błąd. Co do włączania opcji (np. allow_url_fopen) to nie mogę bo nie mam dostepu do php.ini


--------------------
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 09:39:00
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Cytat
Z file_get_contents to mój błąd
Ok, to co ci teraz nie działa?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
djgarsi
post 30.09.2010, 09:42:06
Post #7





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Chodzi mi o jakiś prosty skrypt. Do stron w google napisałem prosty i działa.
  1. $ch = curl_init('http://www.google.pl/search?hl=pl&q=site%3Astrona.pl&btnG=Szukaj&lr=');
  2. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  3. $curl_exec = curl_exec($ch);
  4. preg_match('#<div id=resultStats>.* (.*) .*<nobr>#Ui', $curl_exec, $matches);
  5. curl_close($ch);
  6. $site = $matches[1];
  7. echo $site;


Nie dałoby sie zrobić coś podobnego dla Yahoo?


--------------------
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 09:47:53
Post #8





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Kurcze, czyli CURL ci dziala, masz napisany skrypt ktory też dziala a ty masz nadal problem.
Juz ci napisalem: skrypt co pokazales zwraca xml. W xmlu tym bo podanym przeze mnie wczesniej argumentem znajduje się liczba wyników.

Teraz jedyne co muisz zrobic to sparsowac ten tekst, który jest xmlem. Czy ty to zrobisz przy pomocy bibliotek do XML, czy ty to zrobisz przy pomocy preg_match() to przeciez zaden problem. A widzę preg_match już uzywales wiec czemu i teraz nie uzyjesz?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
djgarsi
post 30.09.2010, 10:31:36
Post #9





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


  1. preg_match('#<div id=totalResultsAvailable>.* (.*) .*<nobr>#Ui', $response, $status_code);
  2. $site2 = $status_code[0];
  3. echo $site2;


o to chodzi?


--------------------
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 10:34:22
Post #10





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




No ale patrzyles jak wygląda ten wygenerowany tekst? No wydaje mi się ze nie, skoro szukasz w DIVach
Cytat
<?xml version="1.0" encoding="UTF-8"?> <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:srchmi" xsi:schemaLocation="urn:yahoo:srchmi http://api.search.yahoo.com/ImageSearchSer...ponse.xsd" totalResultsAvailable="6" totalResultsReturned="6" firstResultPosition="1"> <Result><Title>1235976395 1acac2 jpg</Title><Summary /><Url>http://www.tvoymarket.ru/uploads/posts/2009-03/1235976395_1acac2.jpg</Url><ClickUrl>http://www.tvoymarket.ru/uploads/posts/2009-03/1235976395_1acac2.jpg</ClickUrl><RefererUrl>http://www.tvoymarket.ru/tags/Nospor</RefererUrl><FileSize>28774</FileSize><FileFormat>jpeg</FileFormat><Height>364</Height><Width>260</Width> <Thumbnail><Url>http://thm-a01.yimg.com/nimage/06b4db6b5b409454</Url><Height>135</Height><Width>96</Width></Thumbnail> </Result> <Result><Title>nospor gif</Title><Summary>nexmoz gif 06 Sep 2006 16 23 7k noflun gif 27 Jun 2006 14 48 6k nospor gif 03 May 2002 17 33 7k nowene gif 10 Aug 2002 00 09 6k</Summary><Url>http://www.pl.net/1headings/netnews/nospor.gif</Url><ClickUrl>http://www.pl.net/1headings/netnews/nospor.gif</ClickUrl><RefererUrl>http://www.pl.net/1headings/netnews</RefererUrl><FileSize>7065</FileSize><FileFormat>gif</FileFormat><Height>88</Height><Width>230</Width> <Thumbnail><Url>http://thm-a02.yimg.com/nimage/bf0aead5025e4b3a</Url><Height>49</Height><Width>130</Width></Thumbnail> </Result> <Result><Title>Zwiększ zmniejsz</Title><Summary /><Url>http://nospor.pl/images/arrow_down.png</Url><ClickUrl>http://nospor.pl/images/arrow_down.png</ClickUrl><RefererUrl>http://nospor.pl/</RefererUrl><FileSize>440</FileSize><FileFormat>png</FileFormat><Height>16</Height><Width>16</Width> <Thumbnail><Url>http://thm-a01.yimg.com/nimage/ac91178f49dbc38a</Url><Height>16</Height><Width>16</Width></Thumbnail> </Result> <Result><Title>help png</Title><Summary /><Url>http://nospor.pl/images/help.png</Url><ClickUrl>http://nospor.pl/images/help.png</ClickUrl><RefererUrl>http://nospor.pl/news/show/id/12</RefererUrl><FileSize>864</FileSize><FileFormat>png</FileFormat><Height>16</Height><Width>16</Width> <Thumbnail><Url>http://thm-a02.yimg.com/nimage/25d585cc59da80f6</Url><Height>16</Height><Width>16</Width></Thumbnail> </Result> <Result><Title>nowene gif</Title><Summary>noflun gif 27 Jun 2006 14 48 6k nospor gif 03 May 2002 17 33 7k nowene gif 10 Aug 2002 00 09 6k ntipam gif 31 Jan 2003 14 32 6k</Summary><Url>http://www.pl.net/1headings/netnews/nowene.gif</Url><ClickUrl>http://www.pl.net/1headings/netnews/nowene.gif</ClickUrl><RefererUrl>http://www.pl.net/1headings/netnews</RefererUrl><FileSize>5939</FileSize><FileFormat>gif</FileFormat><Height>88</Height><Width>230</Width> <Thumbnail><Url>http://thm-a01.yimg.com/nimage/615c08fdcac9d650</Url><Height>49</Height><Width>130</Width></Thumbnail> </Result> <Result><Title>noflun gif</Title><Summary>newwor gif 12 Mar 2003 10 17 6k nexmoz gif 06 Sep 2006 16 23 7k noflun gif 27 Jun 2006 14 48 6k nospor gif 03 May 2002 17 33 7k</Summary><Url>http://www.pl.net/1headings/netnews/noflun.gif</Url><ClickUrl>http://www.pl.net/1headings/netnews/noflun.gif</ClickUrl><RefererUrl>http://www.pl.net/1headings/netnews</RefererUrl><FileSize>5836</FileSize><FileFormat>gif</FileFormat><Height>88</Height><Width>230</Width> <Thumbnail><Url>http://thm-a02.yimg.com/nimage/99b639585332661e</Url><Height>49</Height><Width>130</Width></Thumbnail> </Result> </ResultSet> <!-- ws13.ydn.ac4.yahoo.com uncompressed/chunked Thu Sep 30 02:32:43 PDT 2010 -->

Pozatym nie $response a $xml. W kodzie co podales na samym, samym, samym początku tekst jest w zmiennej $xml a nie $response.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
djgarsi
post 30.09.2010, 10:57:11
Post #11





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


  1. preg_match('#<$xml>.* (.*) .*<totalResultsAvailable>#Ui', $curl_exec, $xml);
  2. $site2 = $xml[0];
  3. echo $site2;


Niestety tak nie działa.sad.gif


--------------------
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 11:03:10
Post #12





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




kurcze, ty strzelasz czy jak?
skad ci się nagle w preg_match wzieło curl_exec? Mowilem przeciez ze $xml
  1. preg_match('#<$xml>.* (.*) .*<totalResultsAvailable>#Ui', $xml, $result);
  2. $site2 = $result[0];
  3. echo $site2;

A poprawnosci Twojego wyrażenia już nie sprawdzam

edit:
masz:
  1. preg_match('/totalResultsAvailable="(\d)+"/',$xml, $matches);
  2. echo $matches[1];

Jakoś mi się nie chce wierzyć ze ten skrypt od google to sam napisales jak twierdzisz, jak nawet nie wiesz co do preg_match przekazac


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
djgarsi
post 30.09.2010, 11:08:16
Post #13





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Hm. Jeszcze z linijką $site2 = $result[0]; jest coś nie tak bo wyświetla Notice: Undefined offset: 0


--------------------
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 11:11:23
Post #14





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




bo masz złe wyraznie. W poprzednim poscie podałem ci jak ma wyglądac poprawnie kod do wstawienia, zebys już się nie męczył....


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
djgarsi
post 30.09.2010, 11:18:02
Post #15





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


No dobrze. Działa, jednak nie do końca. skrypt zwraca liczbę 0. Po wrzuceniu do wyszukiwaki yahoo domeny tam pojawia się ponad 1600.
Aha, dodam że appid podaje dobre.

Ten post edytował djgarsi 30.09.2010, 11:19:45


--------------------
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 11:19:07
Post #16





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




No a mi działa smile.gif
Pokaz caly skrypt po zmianach, bo mogłeś cos jeszcze namieszac


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
djgarsi
post 30.09.2010, 11:20:45
Post #17





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


  1. error_reporting(E_ALL);
  2.  
  3. // The Yahoo! Web Services request
  4. $request = 'http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=tu_appid&query=strona.pl&results=1';
  5.  
  6. // Initialize the session
  7. $session = curl_init($request);
  8.  
  9. // Set curl options
  10. curl_setopt($session, CURLOPT_HEADER, true);
  11. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  12.  
  13. // Make the request
  14. $response = curl_exec($session);
  15.  
  16. // Close the curl session
  17. curl_close($session);
  18.  
  19. // Get HTTP Status code from the response
  20. $status_code = array();
  21.  
  22. // Get the XML from the response, bypassing the header
  23. if (!($xml = strstr($response, '<?xml'))) {
  24. $xml = null;
  25. }
  26.  
  27. preg_match('/totalResultsAvailable="(\d)+"/',$xml, $matches);
  28. echo $matches[1];


Ten post edytował djgarsi 30.09.2010, 11:21:25


--------------------
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 11:26:04
Post #18





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




moj blad
nie:(\d)+
a:(\d+)


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
djgarsi
post 30.09.2010, 11:34:57
Post #19





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Niestety nadal jest coś nie tak, bo nawet tak podam strone google.pl to skrypt zwraca mi tylko 5 zamiast ponad 1mln.sad.gif


--------------------
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 11:40:59
Post #20





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




No skrypt juz jest ok. Widac szukajka yahoo zwraca ci tylko tyle. No na to już nic nie poradze smile.gif

ps: a pokaz co zwraca ci
echo $xml;
tylko pokaż źródło strony a nie to co zobaczysz w przeglądarce winksmiley.jpg

ps2:
http://search.yahooapis.com/ImageSearchSer...l&results=1
zwraca 2778 a nie milion winksmiley.jpg


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

2 Stron V   1 2 >
Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 11:41