@@ -157,17 +157,32 @@ def extract_profile(html: str) -> object:
157
157
# get user id
158
158
user_id = navbar .find ('div' , attrs = {'class' : 'ProfileNav' })["data-user-id" ]
159
159
# find tweets count
160
- li_ = navbar .find ('li' , attrs = {'class' : 'ProfileNav-item ProfileNav-item--tweets is-active' })
161
- tweet_count = li_ .find ('span' , attrs = {'class' : 'ProfileNav-value' }).text .strip ()
160
+ try :
161
+ li_ = navbar .find ('li' , attrs = {'class' : 'ProfileNav-item ProfileNav-item--tweets is-active' })
162
+ tweet_count = li_ .find ('span' , attrs = {'class' : 'ProfileNav-value' }).text .strip ()
163
+ except AttributeError :
164
+ tweet_count = 0
165
+
162
166
# find followings
163
- li_ = navbar .find ('li' , attrs = {'class' : 'ProfileNav-item ProfileNav-item--following' })
164
- following_count = li_ .find ('span' , attrs = {'class' : 'ProfileNav-value' }).text .strip ()
167
+ try :
168
+ li_ = navbar .find ('li' , attrs = {'class' : 'ProfileNav-item ProfileNav-item--following' })
169
+ following_count = li_ .find ('span' , attrs = {'class' : 'ProfileNav-value' }).text .strip ()
170
+ except AttributeError :
171
+ following_count = 0
172
+
165
173
# find followers
166
- li_ = navbar .find ('li' , attrs = {'class' : 'ProfileNav-item ProfileNav-item--followers' })
167
- follower_count = li_ .find ('span' , attrs = {'class' : 'ProfileNav-value' }).text .strip ()
174
+ try :
175
+ li_ = navbar .find ('li' , attrs = {'class' : 'ProfileNav-item ProfileNav-item--followers' })
176
+ follower_count = li_ .find ('span' , attrs = {'class' : 'ProfileNav-value' }).text .strip ()
177
+ except AttributeError :
178
+ follower_count = 0
179
+
168
180
# find likes
169
- li_ = navbar .find ('li' , attrs = {'class' : 'ProfileNav-item ProfileNav-item--favorites' })
170
- like_count = li_ .find ('span' , attrs = {'class' : 'ProfileNav-value' }).text .strip ()
181
+ try :
182
+ li_ = navbar .find ('li' , attrs = {'class' : 'ProfileNav-item ProfileNav-item--favorites' })
183
+ like_count = li_ .find ('span' , attrs = {'class' : 'ProfileNav-value' }).text .strip ()
184
+ except AttributeError :
185
+ like_count = 0
171
186
#
172
187
result .append (Profile (
173
188
name = name ,
0 commit comments