如何通过GeoCode(带半径)爬取将Twitter数据直接导入数据库?

2023-12-03

我指的是这个线程:

Twitter - 查询特定地理位置半径内的推文

但我的问题是我想直接将其导入数据库MySQL,而不是System.out.println。 怎么做?

到目前为止我有这个代码:

stmt = conne.prepareStatement("INSERT INTO tweet(ID,date,name,text) VALUES (?,?,?,?)");

stmt.setInt(1, (int) status.getId());

stmt.setString(2, getTimeStamp());

stmt.setString(3, status.getUser().getScreenName());

Query query = new Query("india");
GeoLocation location = new GeoLocation(20.593684, 78.962880);
String unit = Query.KILOMETERS;
    query.setGeoCode(location, 2, unit);
    QueryResult result;
    result = twitter.search(query);
    List<Status> tweets = result.getTweets();
    for (Status tweet : tweets){
stmt.setString(4, status.getText());
                            }

然后,我看到这样的输出错误:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Cannot use this builder any longer, build() has already been called

我发现我有两个build(),这是 TwitterStream 的一个和 TwitterFactory 的一个:

TwitterStream twitterStream5 = new TwitterStreamFactory(cb5.build()).getInstance();
TwitterFactory tf = new TwitterFactory(cb5.build());
Twitter twitter = tf.getInstance();

但我仍然不知道如何纠正它。 感谢您的任何评论!


我发现我有两个 build() ,一个用于 TwitterStream ,一个用于 TwitterFactory :

问题更多的是关于构建器本身:之后你不能重用它build()被称为。您应该有两个独立的构建器。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何通过GeoCode(带半径)爬取将Twitter数据直接导入数据库? 的相关文章

随机推荐