Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php][curl] Liczba stron w Yahoo
Forum PHP.pl > Forum > Przedszkole
djgarsi
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.
nospor
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"
djgarsi
Ok. Tylko że mi na serwerze file_get_contents i simplexml_load nie działa.sad.gif
nospor
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?
djgarsi
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
nospor
Cytat
Z file_get_contents to mój błąd
Ok, to co ci teraz nie działa?
djgarsi
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?
nospor
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?
djgarsi
  1. preg_match('#<div id=totalResultsAvailable>.* (.*) .*<nobr>#Ui', $response, $status_code);
  2. $site2 = $status_code[0];
  3. echo $site2;


o to chodzi?
nospor
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.
djgarsi
  1. preg_match('#<$xml>.* (.*) .*<totalResultsAvailable>#Ui', $curl_exec, $xml);
  2. $site2 = $xml[0];
  3. echo $site2;


Niestety tak nie działa.sad.gif
nospor
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
djgarsi
Hm. Jeszcze z linijką $site2 = $result[0]; jest coś nie tak bo wyświetla Notice: Undefined offset: 0
nospor
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ł....
djgarsi
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.
nospor
No a mi działa smile.gif
Pokaz caly skrypt po zmianach, bo mogłeś cos jeszcze namieszac
djgarsi
  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];
nospor
moj blad
nie:(\d)+
a:(\d+)
djgarsi
Niestety nadal jest coś nie tak, bo nawet tak podam strone google.pl to skrypt zwraca mi tylko 5 zamiast ponad 1mln.sad.gif
nospor
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
djgarsi
Mój błąd.tongue.gif dla google.com dało ponad 1mln.smile.gif

A źródło:
Kod
<?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/ImageSearchService/V1/ImageSearchResponse.xsd" totalResultsAvailable="446" totalResultsReturned="10" firstResultPosition="1">
<Result><Title>twittercounterbig png</Title><Summary /><Url>http://tweerrific.com/wp-content/uploads/2009/05/twittercounterbig.png</Url><ClickUrl>http://tweerrific.com/wp-content/uploads/2009/05/twittercounterbig.png</ClickUrl><RefererUrl>http://tweerrific.com/?p=1</RefererUrl><FileSize>31232</FileSize><FileFormat>png</FileFormat><Height>375</Height><Width>500</Width>
<Thumbnail><Url>http://thm-a01.yimg.com/nimage/43a946631c8eff66</Url><Height>108</Height><Width>145</Width></Thumbnail>
</Result>

<Result><Title>get url php  proxy  url=http   docs google com File id=ddv6dm5b 22ccbrhdc7 b</Title><Summary>Step 5   Setting basic Firefox settings</Summary><Url>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_22ccbrhdc7_b</Url><ClickUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_22ccbrhdc7_b</ClickUrl><RefererUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FDoc%3Fid%3Dddv6dm5b_11f65437hr</RefererUrl><FileSize>140083</FileSize><FileFormat>png</FileFormat><Height>614</Height><Width>1024</Width>

<Thumbnail><Url>http://thm-a02.yimg.com/nimage/36d8e249e2b20500</Url><Height>95</Height><Width>160</Width></Thumbnail>
</Result>

<Result><Title>get url php  proxy  url=http   docs google com File id=ddv6dm5b 24grzxrqgc b</Title><Summary>Step 6   The advantages of being a registered user</Summary><Url>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_24grzxrqgc_b</Url><ClickUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_24grzxrqgc_b</ClickUrl><RefererUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FDoc%3Fid%3Dddv6dm5b_11f65437hr</RefererUrl><FileSize>188723</FileSize><FileFormat>png</FileFormat><Height>543</Height><Width>984</Width>

<Thumbnail><Url>http://thm-a01.yimg.com/nimage/80d01edec91cbb68</Url><Height>88</Height><Width>160</Width></Thumbnail>
</Result>

<Result><Title>get url php  proxy  url=http   docs google com File id=ddv6dm5b 23drg956fp b</Title><Summary /><Url>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_23drg956fp_b</Url><ClickUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_23drg956fp_b</ClickUrl><RefererUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FDoc%3Fid%3Dddv6dm5b_11f65437hr</RefererUrl><FileSize>113254</FileSize><FileFormat>png</FileFormat><Height>614</Height><Width>1024</Width>

<Thumbnail><Url>http://thm-a02.yimg.com/nimage/8f54a2141785545c</Url><Height>95</Height><Width>160</Width></Thumbnail>
</Result>

<Result><Title>get url php  proxy  url=http   docs google com File id=ddv6dm5b 18c59996db b</Title><Summary>We are not graphic designers  so he  Fashion Your Firefox  web pages came in handy to illustrate our points  a big thank you to the designers  Step 1   Specifying the target O S</Summary><Url>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_18c59996db_b</Url><ClickUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_18c59996db_b</ClickUrl><RefererUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FDoc%3Fid%3Dddv6dm5b_11f65437hr</RefererUrl><FileSize>83763</FileSize><FileFormat>png</FileFormat><Height>614</Height><Width>1024</Width>

<Thumbnail><Url>http://thm-a01.yimg.com/nimage/14d2aaced0088a74</Url><Height>95</Height><Width>160</Width></Thumbnail>
</Result>

<Result><Title>get url php  proxy  url=http   docs google com File id=ddv6dm5b 17ckxpz9c6 b</Title><Summary>The walk through process  from Firefox to My Firefox</Summary><Url>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_17ckxpz9c6_b</Url><ClickUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_17ckxpz9c6_b</ClickUrl><RefererUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FDoc%3Fid%3Dddv6dm5b_11f65437hr</RefererUrl><FileSize>133017</FileSize><FileFormat>jpeg</FileFormat><Height>610</Height><Width>958</Width>

<Thumbnail><Url>http://thm-a02.yimg.com/nimage/9b80894a08da1112</Url><Height>101</Height><Width>160</Width></Thumbnail>
</Result>

<Result><Title>get url php  proxy  url=http   docs google com File id=ddv6dm5b 19g3gnvqf5 b</Title><Summary>Step 2  Customizing the look</Summary><Url>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_19g3gnvqf5_b</Url><ClickUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_19g3gnvqf5_b</ClickUrl><RefererUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FDoc%3Fid%3Dddv6dm5b_11f65437hr</RefererUrl><FileSize>97484</FileSize><FileFormat>png</FileFormat><Height>614</Height><Width>1024</Width>

<Thumbnail><Url>http://thm-a01.yimg.com/nimage/a2b7ca98572b13b6</Url><Height>95</Height><Width>160</Width></Thumbnail>
</Result>

<Result><Title>get url php  proxy  url=http   docs google com File id=ddv6dm5b 20d65kk6d6 b</Title><Summary>Step 3   Selecting the browsing scenarios</Summary><Url>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_20d65kk6d6_b</Url><ClickUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_20d65kk6d6_b</ClickUrl><RefererUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FDoc%3Fid%3Dddv6dm5b_11f65437hr</RefererUrl><FileSize>171520</FileSize><FileFormat>png</FileFormat><Height>614</Height><Width>1024</Width>

<Thumbnail><Url>http://thm-a02.yimg.com/nimage/01940f4b934fedfc</Url><Height>95</Height><Width>160</Width></Thumbnail>
</Result>

<Result><Title>get url php  proxy  url=http   docs google com File id=ddv6dm5b 25f2p8k3fd b</Title><Summary>Feasability</Summary><Url>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_25f2p8k3fd_b</Url><ClickUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_25f2p8k3fd_b</ClickUrl><RefererUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FDoc%3Fid%3Dddv6dm5b_11f65437hr</RefererUrl><FileSize>107724</FileSize><FileFormat>jpeg</FileFormat><Height>617</Height><Width>955</Width>

<Thumbnail><Url>http://thm-a01.yimg.com/nimage/fed4719530cc132a</Url><Height>103</Height><Width>160</Width></Thumbnail>
</Result>

<Result><Title>get url php  proxy  url=http   docs google com File id=ddv6dm5b 21g9v654hb b</Title><Summary>Step 4   Importing bookmarks</Summary><Url>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_21g9v654hb_b</Url><ClickUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FFile%3Fid%3Dddv6dm5b_21g9v654hb_b</ClickUrl><RefererUrl>http://www.behidden.com/get_url.php?&amp;amp;proxy__url=http%3A%2F%2Fdocs.google.com%2FDoc%3Fid%3Dddv6dm5b_11f65437hr</RefererUrl><FileSize>133734</FileSize><FileFormat>png</FileFormat><Height>614</Height><Width>1024</Width>

<Thumbnail><Url>http://thm-a02.yimg.com/nimage/202ba96cda3131d4</Url><Height>95</Height><Width>160</Width></Thumbnail>
</Result>
</ResultSet>
<!-- ws01.ydn.ac4.yahoo.com uncompressed/chunked Thu Sep 30 03:43:31 PDT 2010 -->
nospor
No i jak sam widzisz yahoo zwraca ci tylko 446
totalResultsAvailable="446"
Skrypt działa. Teraz idź się zapytaj yahoo czemu zwraca ci inne wyniki smile.gif
djgarsi
Dobra dobra.tongue.gif Nie kozacz.smile.gif Wychodzi na to że yahoo sobie olewa api.smile.gif Dzieki za skrypt.smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.