回答編集履歴

2

追記

2018/09/01 14:40

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -17,6 +17,14 @@
17
17
  乗り掛かった舟なので、ちょっと手元で試してみました。
18
18
 
19
19
  次の手段でハッシュタグを取得できます。
20
+
21
+
22
+
23
+ ##### 手元の環境
24
+
25
+ - Microsoft Windows [Version 10.0.17134.228]
26
+
27
+ - Python 3.6.6 :: Anaconda, Inc.
20
28
 
21
29
 
22
30
 
@@ -70,11 +78,17 @@
70
78
 
71
79
  for tweet in tweets:
72
80
 
81
+ hash_tags = [
82
+
73
- hash_tags = [tag.lstrip('#') for tag in tweet.hashtags.split()]
83
+ tag.lstrip('#') for tag in tweet.hashtags.split()
84
+
85
+ if tag != '#'
86
+
87
+ ]
88
+
89
+
74
90
 
75
91
  print(hash_tags)
76
-
77
-
78
92
 
79
93
  ```
80
94
 
@@ -100,7 +114,7 @@
100
114
 
101
115
  ['牛丼', '吉野家', '冷凍', '送料無料', '楽天', '夏', '暑い', '熱中症']
102
116
 
103
- ['', '熱中症注意', '熱中症予防', '熱中症対策', '猛暑', '熱中症']
117
+ ['熱中症注意', '熱中症予防', '熱中症対策', '猛暑', '熱中症']
104
118
 
105
119
  ['薬', '薬剤師', '熱中症', '調剤薬局', '脱水', '経口補水液', '脱水症状']
106
120
 

1

追記

2018/09/01 14:39

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -7,3 +7,125 @@
7
7
  import itertools
8
8
 
9
9
  ```
10
+
11
+
12
+
13
+ 追記
14
+
15
+ ---
16
+
17
+ 乗り掛かった舟なので、ちょっと手元で試してみました。
18
+
19
+ 次の手段でハッシュタグを取得できます。
20
+
21
+
22
+
23
+ ##### GetOldTweetsを改造
24
+
25
+ Twitterの仕様が変わったのか分かりませんが、現状まともにハッシュタグを取得できていません。
26
+
27
+ 次のように[got3.manager.TweetManager.pyの39行目のコード](https://github.com/Jefferson-Henrique/GetOldTweets-python/blob/master/got3/manager/TweetManager.py#L34)を置き換えます。
28
+
29
+ ```Python
30
+
31
+ # txt = re.sub(r"\s+", " ", tweetPQ("p.js-tweet-text").text().replace('# ', '#').replace('@ ', '@'))
32
+
33
+
34
+
35
+ txt = tweetPQ("p.js-tweet-text").text()
36
+
37
+ txt = re.sub(r"#\s?", '#', txt)
38
+
39
+ txt = re.sub(r"@\s?", '@', txt)
40
+
41
+ txt = re.sub(r"\s+", ' ', txt)
42
+
43
+ ```
44
+
45
+
46
+
47
+ ##### 実行コード
48
+
49
+ ```Python
50
+
51
+ import got3 as got
52
+
53
+
54
+
55
+ tweet_criteria = got.manager.TweetCriteria() \
56
+
57
+ .setQuerySearch('#熱中症') \
58
+
59
+ .setSince("2018-07-10") \
60
+
61
+ .setUntil("2018-08-30") \
62
+
63
+ .setMaxTweets(10)
64
+
65
+
66
+
67
+ tweets = got.manager.TweetManager.getTweets(tweet_criteria)
68
+
69
+
70
+
71
+ for tweet in tweets:
72
+
73
+ hash_tags = [tag.lstrip('#') for tag in tweet.hashtags.split()]
74
+
75
+ print(hash_tags)
76
+
77
+
78
+
79
+ ```
80
+
81
+
82
+
83
+ 上記のコードを実行したところ、次の結果が得られました。
84
+
85
+ ```plain
86
+
87
+ ['熱中症', '熱中症対策', '暑い', 'ブログ更新http']
88
+
89
+ ['介護', '熱中症']
90
+
91
+ ['関東', '天気', '熱中症']
92
+
93
+ ['熱中症']
94
+
95
+ ['熱中症']
96
+
97
+ ['めまい', '嘔吐', '熱中症', '痙攣', '筋肉痛']
98
+
99
+ ['熱中症']
100
+
101
+ ['牛丼', '吉野家', '冷凍', '送料無料', '楽天', '夏', '暑い', '熱中症']
102
+
103
+ ['', '熱中症注意', '熱中症予防', '熱中症対策', '猛暑', '熱中症']
104
+
105
+ ['薬', '薬剤師', '熱中症', '調剤薬局', '脱水', '経口補水液', '脱水症状']
106
+
107
+ ```
108
+
109
+
110
+
111
+ これのcombinationを取れば、上手くいくはず。
112
+
113
+
114
+
115
+ ただし
116
+
117
+ ---
118
+
119
+ GetOldTweetsは、Python3.x向けにはろくにメンテナンスされていないようです。
120
+
121
+ (エラーの内容を見るに、2系でも正常に動くか疑問です。)
122
+
123
+ > This package assumes using Python 2.x. **The Python3 "got3" folder is maintained as experimental and is not officially supported**.
124
+
125
+
126
+
127
+ 引用元: [GetOldTweets-python/README.md](https://github.com/Jefferson-Henrique/GetOldTweets-python/blob/master/README.md) **太字**は引用者
128
+
129
+
130
+
131
+ 代替策が特に提示できなく申し訳ないのですが、**別の方法を検討されることをお勧めします。**