scrape_creators 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/scrape_creators/client.rb +46 -4
- data/lib/scrape_creators/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c214fa7c8b7b56a2483d3432420003745f73747e8391100312168466f9f03c7b
|
|
4
|
+
data.tar.gz: 0ec20deecab206e3ba0f54707abbfee7e624485d5f7954311bdb34552b207f40
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f15f5722980fca1ccb48a32e1d62927324ae944c81132cc3210f2a35d12209033ef244804c988a9f4b3924c28f78c9ddca63bf66e29dd0e24e9477195ad95aed
|
|
7
|
+
data.tar.gz: 20aadfbd40d3362a8d6fbbe52223fb1bb4baafdaec99406e9a9bbe477e8ab1fd40b29bf7279fdfc813a88c3126237a5bd598bf7ccf2db5c0adb133e7c79d4c66
|
data/README.md
CHANGED
|
@@ -50,6 +50,16 @@ info = scraper.post("https://www.instagram.com/p/DKSMEpKRd6h/", download_media:
|
|
|
50
50
|
|
|
51
51
|
```ruby
|
|
52
52
|
comments = scraper.comments("https://www.instagram.com/p/DKSMEpKRd6h/")
|
|
53
|
+
|
|
54
|
+
page = scraper.comments_page("https://www.instagram.com/p/DKSMEpKRd6h/")
|
|
55
|
+
page[:comments]
|
|
56
|
+
page[:cursor]
|
|
57
|
+
page[:has_more]
|
|
58
|
+
|
|
59
|
+
next_page = scraper.comments_page(
|
|
60
|
+
"https://www.instagram.com/p/DKSMEpKRd6h/",
|
|
61
|
+
cursor: page[:cursor]
|
|
62
|
+
)
|
|
53
63
|
```
|
|
54
64
|
|
|
55
65
|
## License
|
|
@@ -73,12 +73,31 @@ module ScrapeCreators
|
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
def comments(url_or_code, options = {})
|
|
76
|
+
comments_page(url_or_code, options)[:comments]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def comments_page(url_or_code, options = {})
|
|
76
80
|
source = (options[:source] || 'instagram').to_s
|
|
77
81
|
url = normalize_url(url_or_code)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
extra = options.reject { |k, _| %w[source cursor continuationToken continuation_token].include?(k.to_s) }
|
|
83
|
+
params = { url: url }.merge(extra)
|
|
84
|
+
cursor = options[:cursor] || options['cursor'] || options[:continuationToken] || options['continuationToken'] || options[:continuation_token]
|
|
85
|
+
if cursor && !cursor.to_s.empty?
|
|
86
|
+
if source == YOUTUBE
|
|
87
|
+
params[:continuationToken] = cursor
|
|
88
|
+
else
|
|
89
|
+
params[:cursor] = cursor
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
res = get(comments_url_for(source: source), params)
|
|
94
|
+
comments = res.is_a?(Hash) ? (res['comments'] || []) : []
|
|
95
|
+
next_cursor = next_comments_cursor(res, source)
|
|
96
|
+
{
|
|
97
|
+
comments: comments,
|
|
98
|
+
cursor: next_cursor,
|
|
99
|
+
has_more: comments_has_more?(res, source, next_cursor)
|
|
100
|
+
}
|
|
82
101
|
end
|
|
83
102
|
|
|
84
103
|
def get(endpoint, params = {}, options = {})
|
|
@@ -121,6 +140,29 @@ module ScrapeCreators
|
|
|
121
140
|
|
|
122
141
|
private
|
|
123
142
|
|
|
143
|
+
def next_comments_cursor(res, source)
|
|
144
|
+
return nil unless res.is_a?(Hash)
|
|
145
|
+
|
|
146
|
+
cursor = if source == YOUTUBE
|
|
147
|
+
res['continuationToken']
|
|
148
|
+
else
|
|
149
|
+
res['cursor']
|
|
150
|
+
end
|
|
151
|
+
return nil if cursor.nil? || cursor.to_s.empty?
|
|
152
|
+
|
|
153
|
+
cursor
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def comments_has_more?(res, source, next_cursor)
|
|
157
|
+
return false unless res.is_a?(Hash)
|
|
158
|
+
|
|
159
|
+
if source == TIKTOK
|
|
160
|
+
res['has_more'].to_i == 1
|
|
161
|
+
else
|
|
162
|
+
!next_cursor.nil?
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
124
166
|
def normalize_url(url_or_code)
|
|
125
167
|
str = url_or_code.to_s.strip
|
|
126
168
|
if str.start_with?('http://', 'https://')
|