Yahoo! search interface: Difference between revisions
Content added Content deleted
(add task to ARM64 assembly Raspberry Pi) |
|||
Line 1,790: | Line 1,790: | ||
$invocant->{results} = $results; |
$invocant->{results} = $results; |
||
return 1;}</lang> |
return 1;}</lang> |
||
=={{header|Phix}}== |
|||
<lang Phix>-- demo\rosetta\Yahoo_search_interface.exw |
|||
include builtins\libcurl.e |
|||
constant glyphs = {{"\xC2\xB7 ","*"}, -- bullet point |
|||
{"'",`'`}, -- single quote |
|||
{""",`"`}, -- double quote |
|||
{"&","&"}, -- ampersand |
|||
{"\xE2\x94\xAC\xC2\xAB","[R]"}, -- registered |
|||
{"\xC2\xAE","[R]"}}, -- registered |
|||
{gutf8,gascii} = columnize(glyphs), |
|||
tags = {{`<a `,`</a>`}, |
|||
{`<b>`,`</b>`}, |
|||
{`<span class=" fc-2nd">`,`</span>`}} |
|||
function grab(string txt, opener, closer, integer tdx) |
|||
integer openidx = match(opener,txt,tdx) |
|||
if openidx=0 then return {0,""} end if |
|||
integer closeidx = match(closer,txt,openidx) |
|||
txt = txt[openidx+length(opener)..closeidx-1] |
|||
tdx = 1 |
|||
while tdx<=length(tags) do |
|||
{opener,closer} = tags[tdx] |
|||
integer i = match(opener,txt) |
|||
if i=0 then |
|||
tdx += 1 |
|||
else |
|||
if opener[$]='>' then |
|||
txt[i..i+length(opener)-1] = "" |
|||
else |
|||
txt[i..find('>',txt,i)] = "" |
|||
end if |
|||
i = match(closer,txt,i) |
|||
txt[i..i+length(closer)-1] = "" |
|||
end if |
|||
end while |
|||
txt = substitute_all(txt,gutf8,gascii) |
|||
if length(txt)>80 then txt[78..$] = ".." end if |
|||
return {closeidx+length(closer),txt} |
|||
end function |
|||
procedure YahooSearch(string query, integer page=1) |
|||
printf(1,"Page %d:\n=======\n",page) |
|||
string url = sprintf("https://search.yahoo.com/search?p=%s&b=%d", {query, (page-1)*10+1}) |
|||
object res = curl_easy_perform_ex(url) |
|||
if not string(res) then |
|||
?{"some error",res,curl_easy_strerror(res)} |
|||
return |
|||
end if |
|||
integer rdx = 1 |
|||
string title, link, desc |
|||
while true do |
|||
{rdx,title} = grab(res,`<h3 class="title ov-h">`,`</h3>`,rdx) |
|||
if rdx=0 then exit end if |
|||
{rdx,link} = grab(res,`<span class=" fz-ms fw-m fc-12th wr-bw lh-17">`,`</span>`,rdx) |
|||
{rdx,desc} = grab(res,`<p class="fz-ms lh-1_43x">`,`</p>`,rdx) |
|||
printf(1,"title:%s\nlink:%s\ndesc:%s\n\n",{title,link,desc}) |
|||
end while |
|||
end procedure |
|||
YahooSearch("rosettacode") |
|||
YahooSearch("rosettacode",2)</lang> |
|||
{{out}} |
|||
<pre> |
|||
Page 1: |
|||
======= |
|||
title:Rosetta Code |
|||
link:rosettacode.org |
|||
desc:Jan 29, 2016 * Rosetta Code is a programming chrestomathy site. The idea is t.. |
|||
title:Rosetta Code - Wikipedia |
|||
link:en.wikipedia.org/wiki/Rosetta_Code |
|||
desc:Rosetta Code is a wiki -based programming website with implementations of com.. |
|||
title:@rosettacode | Twitter |
|||
link:twitter.com/rosettacode |
|||
desc:The latest tweets from @rosettacode |
|||
title:Rosetta Code - Simple English Wikipedia, the free encyclopedia |
|||
link:simple.wikipedia.org/wiki/Rosetta_Code |
|||
desc:Rosetta Code is a wiki-based website that features ways to solve various prog.. |
|||
<snip> |
|||
Page 2: |
|||
======= |
|||
title:Category:Guile - Rosetta Code |
|||
link:rosettacode.org/wiki/Category:Guile |
|||
desc:May 30, 2020 * Listed below are all of the tasks on Rosetta Code which have b.. |
|||
title:Rosetta Code - c2.com |
|||
link:wiki.c2.com/?RosettaCode |
|||
desc:Rosetta Code is a repository for code examples that go beyond the traditional.. |
|||
<snip> |
|||
title:Rosetta Stone | Discovery, History, & Facts | Britannica |
|||
link:www.britannica.com/topic/Rosetta-Stone |
|||
desc:Rosetta Stone, ancient Egyptian stone bearing inscriptions in several languag.. |
|||
</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |