我不知道如何用jsoup更新twitter时间线。任何人都可以帮助我吗?
时间轴每隔几秒更新一次,我有这段代码来检索当前时间轴但是如何每隔几秒更新一次。
void searchTweet() throws IOException {
List<Tweets> tweetList = new ArrayList<>();
Response response = Jsoup.connect("https://twitter.com").userAgent(userAgent).cookies(cookies).execute();
Element streamTag = response.parse().getElementById("stream-items-id");
String id;
String tweet_stat_count;
Elements li = streamTag.getElementsByAttributeValue("data-item-type", "tweet");
for (Element elementOfLiTag : li) {
Elements span = elementOfLiTag.select("span.ProfileTweet-actionCount");
id = elementOfLiTag.attr("data-item-id");
tweet_stat_count = span.get(1).attr("data-tweet-stat-count");
String text = elementOfLiTag.getElementsByClass("TweetTextSize").text();
}
}
答案 0 :(得分:0)
如果您想每隔几秒钟调用一次任务,则可以使用ScheduledThreadPoolExecutor
:
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1);
executor.schedule(this::searchTweet, 5, TimeUnit.SECOND);