Last active
January 7, 2017 03:04
-
-
Save gn-spawn/0a69277b781f73832880e0f323002c5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ArrayList<String> getTweets(String hashtag, String user_name) { | |
NodeList nodeList = null; | |
ArrayList<String> tweets = new ArrayList<String>(); | |
try { | |
URL url = new URL("https://queryfeed.net/tw?q=%23" + URLEncoder.encode(hashtag, "UTF-8") + "+%40" + user_name + "&title-type=user-name-both&geocode="); | |
URLConnection urlConnection = url.openConnection(); | |
urlConnection.connect(); | |
InputStream inputStream = urlConnection.getInputStream(); | |
// DOM取得 | |
DocumentViewer documentViewer = new DocumentViewer(); | |
Document document = documentViewer.buildDocument(inputStream, "UTF-8"); | |
nodeList = document.getElementsByTagName("description"); | |
for (int i = 0; i < nodeList.getLength(); i++) { | |
String value = nodeList.item(i).getFirstChild().getNodeValue(); | |
tweets.add(i, value.replaceAll("<.+?>", "")); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return tweets; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// main文で使う例
ArrayList tweets = mashup.getTweets("スポーンメモ", "gn_spawn");
for (String tweet : tweets) {
System.out.println(tweet);
}