Yahoo! search interface: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Phix}}: syntax coloured, fixed to work with current output.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 7:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program yahoosearch64.s */
Line 373:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
{{Output}}
<pre>
Line 383:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program yahoosearch.s */
Line 735:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
{{Output}}
<pre>
Line 744:
=={{header|AutoHotkey}}==
translated from python example
<syntaxhighlight lang="autohotkey">test:
yahooSearch("test", 1)
yahooSearch("test", 2)
Line 774:
url := regexreplace(url, "<.*?>")
return url
}</
=={{header|C sharp}}==
Line 780:
E. g. all implementations for this task which regex for
"<a class=" fail by now, after Yahoo has changed its output format.
<
using System.Net;
using System.Text.RegularExpressions;
Line 893:
}
}
</syntaxhighlight>
=={{header|D}}==
{{trans|C#}}
<
std.net.curl;
Line 955:
void main() {
writefln("%(%s\n%)", "test".YahooSearch.results);
}</
{{out|Output (shortened)}}
<pre>
Line 973:
=={{header|Gambas}}==
<
Dim hWebView As WebView
Line 984:
hWebView.URL = "https://www.yahoo.com"
End</
'''[http://www.cogier.com/gambas/Yahoo!%20search%20interface.png Click here to see output (I have typed 'rosettacode' in the search box)]'''
Line 991:
The regular expression used below was figured out by studying the raw HTML and works fine as at 18th November, 2019.
<
import (
Line 1,053:
fmt.Println(res)
}
}</
{{out}}
Line 1,105:
=={{header|GUISS}}==
<
Button:Go,Area:browser window,Inputbox:searchbox>elephants,Button:Search</
=={{header|Haskell}}==
Haskell is not an object oriented language, so this example does not implement an object class.
However, it can be interesting as an example of how HTML source code can be parsed using the Parsec library.
<
import Text.Parsec
Line 1,216:
in [ YahooSearchItem { itemUrl = u, itemTitle = t, itemContent = c } |
(u, t, c) <- zip3 us ts cs ]
</syntaxhighlight>
Simple invocation from GHCi: <pre>yahoo "Rosetta%20code" >>= printResults</pre>. Notice that spaces must be expressed as "%20", because spaces are not allowed in URLs.
==Icon and {{header|Unicon}}==
The following uses the Unicon pre-processor and messaging extensions and won't run under Icon without significant modification.
The code provides a suitable demonstration; however, could be made more robust by things such as URL escaping the search string
<
procedure main()
Line 1,263:
urlpat := sprintf("http://search.yahoo.com/search?p=%s&b=%%d",searchtext)
page := 0
end</
{{libheader|Icon Programming Library}}
Line 1,304:
=={{header|Java}}==
{{incorrect|Java}}
<
import java.io.IOException;
import java.io.InputStreamReader;
Line 1,460:
}
}
}</
=={{header|Julia}}==
<
using EzXML
Line 1,541:
println("URL: ", res.url, "\n")
end
</
<pre>
Searching Yahoo for `RosettaCode`:
Line 1,707:
{{incorrect|Kotlin}}
This is based on the C# entry but uses a regular expression based on what appears to be the Yahoo! format as at the date of this entry (4 December 2017).
<
import java.net.URL
Line 1,751:
for (result in x.results.take(3)) println(result)
}
}</
Output (restricted to first three results on first two pages):
<pre>PAGE 1 =>
Line 1,783:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
We cannot define a class in Mathematica, so I generate a "Manipulate" object instead.
<syntaxhighlight lang="text">Manipulate[
Column[Flatten[
StringCases[
Line 1,807:
Row[{Button["Search", page = 1; query = input],
Button["Prev", page -= 10, Enabled -> Dynamic[page >= 10]],
Button["Next", page += 10]}]]</
=={{header|Nim}}==
<
const
PageSize = 7
Line 1,864:
searchInf.nextPage()
searchInf.echoResult()
</syntaxhighlight>
{{out}}
<pre>(url: "https://weather.com/", title: "National and Local Weather Radar, Daily Forecast, Hurricane ...", content: "The Weather Channel and weather.com provide a national and local weather forecast for cities, as well as weather radar, report and hurricane coverage ")
Line 1,890:
We implement some simple parsing with logic programming. Regular expressions in Oz don't seem to support lazy quantification which makes parsing the result pages with them difficult.
<
[HTTPClient] = {Module.link ['x-ozlib://mesaros/net/HTTPClient.ozf']}
[StringX] = {Module.link ['x-oz://system/String.ozf']}
Line 2,036:
end
in
{ExampleUsage}</
=={{header|Perl}}==
<
use Encode;
Line 2,106:
$invocant->{link_to_next} = $next;
$invocant->{results} = $results;
return 1;}</
=={{header|Phix}}==
Line 2,120:
{"\xC2\xAE","[R]"}}, -- registered
</pre>
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Yahoo_search_interface.exw
Line 2,198:
<span style="color: #0000FF;">?</span><span style="color: #008000;">"done"</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</
{{out}}
<pre>
Line 2,239:
=={{header|PicoLisp}}==
<
(de yahoo (Query Page)
Line 2,263:
(T (eof))
(T (= "</div" (till ">" T)))
(char) ) ) ) ) ) ) ) ) ) )</
Output:
<pre>: (more (yahoo "test"))
Line 2,273:
=={{header|Python}}==
<
import re
Line 2,317:
for result in x.search_results:
print result.title</
=={{header|R}}==
Line 2,325:
Rather than using regexes to find the content (like some of the other solutions here) this method parses the HTML and finds the appropriate sections.
<
{
if(!require(RCurl) || !require(XML))
Line 2,414:
#Usage
YahooSearch("rosetta code")
nextpage()</
=={{header|Racket}}==
<
(require net/url)
(define *yaho-url* "http://search.yahoo.com/search?p=~a&b=~a")
Line 2,445:
(define (next-page)
(set! *current-page* (add1 *current-page*))
(search-yahoo *current-query*))</
# REPL:
Line 2,523:
YahooSearch.rakumod:
<syntaxhighlight lang="raku" line>
use Gumbo;
use LWP::Simple;
Line 2,579:
YahooSearch.new($search-term).results.next.results;
}
</syntaxhighlight>
And the invocation script is simply:
Line 2,590:
Should give out something like the following:
<syntaxhighlight lang="text">
=== #1 ===
Title:
Line 2,603:
URL: https://video.search.yahoo.com/search/video?p=test
Text: More Test videos
</syntaxhighlight>
...and should go up to result #21!
Line 2,610:
{{improve|1=Ruby|2=Should not call <code>URI.escape</code>, because it fails to encode = signs and some other characters that might appear in the term. See [[URL encoding#Ruby]].}}
Uses {{libheader|RubyGems}} {{libheader|Hpricot}} to parse the HTML. Someone more skillful than I at XPath or CSS could tighten up the <code>parse_html</code> method.
<
require 'hpricot'
Line 2,672:
puts result.content
puts
end</
=={{header|Run BASIC}}==
<
' send this from the server to the clients browser
'--------------------------------------------------------------------------
Line 2,712:
[exit]
cls ' clear browser screen and get outta here
wait</
This user input sits at the top of the yahoo page so they can select a new search or page
<div>[[File:yahooSearchRunBasic.png]]</div>
Line 2,719:
{{trans|Python}}
<
proc fix s {
Line 2,756:
foreach {title content url} [Nextpage] {
puts $title
}</
{{works with|Tcl|8.6}}
With Tcl 8.6, more options are available for managing the global state, through objects and coroutines. First, an object-based solution that takes the basic <tt>YahooSearch</tt> functionality and dresses it up to be more Tcl-like:
<
oo::class create WebSearcher {
Line 2,792:
puts "\"$title\" : $url"
}
$ytest delete ;# standard method that deletes the object</
However, the paradigm of an iterator is also interesting and is more appropriately supported through a coroutine. This version conceals the fact that the service produces output in pages; care should be taken with it because it can produce rather a lot of network traffic...
<
proc yahoo! term {
Line 2,816:
puts [dict get [$it] title]
after 300 ;# Slow the code down... :-)
}</
Another approach: uses a class as specified in the task. Also, uses an html parser from tcllib (parsing html with regular expressions is a particular annoyance of [[User:Glennj|mine]]).
Line 2,823:
{{tcllib|htmlparse}}
{{tcllib|textutil::adjust}}<!-- for formatting output -->
<
package require http
package require htmlparse
Line 2,936:
puts ""
}
}</
=={{header|TXR}}==
Line 2,946:
A little sprinkling of regex is used.
<
@(next :args)
@(cases)
Line 2,968:
@ (end)
@(end)
</syntaxhighlight>
Sample run:
Line 3,022:
A somewhat ''ad hoc'' solution as the output format for Yahoo! search seems to change quite frequently. All I can say is that this worked on 5th January, 2022.
<
import "./pattern" for Pattern
Line 3,107:
}
System.print("Displayed %(limit) pages with a total of %(totalCount) entries.")
curl.easyCleanup()</
<br>
We now embed this script in the following C program, build and run.
<
#include <stdio.h>
Line 3,300:
free(script);
return 0;
}</
{{out}}
|