De Twitter search atom heeft de volgende vorm:
Met behulp van onderstaande jQuery code haal ik (via php curl) deze zoekresultaten binnen en loop ik erdoorheen:
Probleem: zowel in regel 4 als 8 staat een "link" attribuut, zij de eerste met type "text/html" en de tweede met "image/png". Ik wil in de loop de href-value van de tweede link pakken, in dit geval dus:
Het vreemde is alleen (zie jQuery code) dat de alert alleen de eerste link ("text/html") alert; het tweede link attribuut wordt niet ge-alert. Mijn vraag is: weet iemand waarom?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| <?xml version="1.0" encoding="UTF-8"?> <feed xmlns:google="http://base.google.com/ns/1.0" xml:lang="en-US" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.w3.org/2005/Atom" xmlns:twitter="http://api.twitter.com/"> <id>tag:search.twitter.com,2005:search/$goog</id> <link type="text/html" href="http://search.twitter.com/search?q=%24goog" rel="alternate"/> <link type="application/atom+xml" href="http://search.twitter.com/search.atom?q=$goog" rel="self"/> <title>$goog - Twitter Search</title> <link type="application/opensearchdescription+xml" href="http://search.twitter.com/opensearch.xml" rel="search"/> <link type="application/atom+xml" href="http://search.twitter.com/search.atom?q=%24goog&since_id=12338503698" rel="refresh"/> <twitter:warning>since_id removed for pagination.</twitter:warning> <updated>2010-04-17T12:21:37Z</updated> <openSearch:itemsPerPage>15</openSearch:itemsPerPage> <link type="application/atom+xml" href="http://search.twitter.com/search.atom?max_id=12338503698&page=2&q=%24goog" rel="next"/> <entry> <id>tag:search.twitter.com,2005:12336213327</id> <published>2010-04-17T11:07:50Z</published> <link type="text/html" href="http://twitter.com/sizzleindex/statuses/12336213327" rel="alternate"/> <title>The Motley Fool's Weekly Editors' Picks (at Motley Fool): http://bit.ly/cQn2w0 $goog $aapl</title> <content type="html">The Motley Fool&apos;s Weekly Editors&apos; Picks (at Motley Fool): <a href="http://bit.ly/cQn2w0">http://bit.ly/cQn2w0</a> <b>$goog</b> $aapl</content> <updated>2010-04-17T11:07:50Z</updated> <link type="image/png" href="http://a3.twimg.com/profile_images/745027829/bullmarket_normal.jpg" rel="image"/> <twitter:geo> </twitter:geo> <twitter:metadata> <twitter:result_type>recent</twitter:result_type> </twitter:metadata> <twitter:source><a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a></twitter:source> <twitter:lang>en</twitter:lang> <author> <name>sizzleindex (Profit From Trading)</name> <uri>http://twitter.com/sizzleindex</uri> </author> </entry> ...knip! |
Met behulp van onderstaande jQuery code haal ik (via php curl) deze zoekresultaten binnen en loop ik erdoorheen:
JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| function getSearch() { var results = ""; var theQuery = $('textarea[name=symbols]').val(); $.post("getSearch.php", {query: theQuery}, function(xml) { $('entry',xml).each(function(i) { var title = $(this).find("content").text(); var linktype = $(this).find("link").attr("type"); alert(linktype); results = results + title + "<br>"; }); $("#tweets").html(results); }); $('#countdown').countdown({seconds: 30, callback: 'getSearch()'}); } |
Probleem: zowel in regel 4 als 8 staat een "link" attribuut, zij de eerste met type "text/html" en de tweede met "image/png". Ik wil in de loop de href-value van de tweede link pakken, in dit geval dus:
code:
1
| http://a3.twimg.com/profile_images/745027829/bullmarket_normal.jpg |
Het vreemde is alleen (zie jQuery code) dat de alert alleen de eerste link ("text/html") alert; het tweede link attribuut wordt niet ge-alert. Mijn vraag is: weet iemand waarom?
"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."