我正在尝试从字符串列表中提取工资。我正在使用正则表达式 findall() 函数,但它返回许多空字符串以及薪水,这导致我稍后在代码中出现问题。
sal= '41 000€ à 63 000€ / an' #this is a sample string for which i have errors
regex = ' ?([0-9]* ?[0-9]?[0-9]?[0-9]?)'#this is my regex
re.findall(regex,sal)[0]
#returns '41 000' as expected but:
re.findall(regex,sal)[1]
#returns: ''
#Desired result : '63 000'
#the whole list of matches is like this:
['41 000',
'',
'',
'',
'',
'',
'',
'63 000',
'',
'',
'',
'',
'',
'',
'',
'',
'']
# I would prefer ['41 000','63 000']
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮忙吗?谢谢
您好,我正在尝试使用 tweepy 抓取某个用户的推文。这是我的代码:
tweets = []
username = 'example'
count = 140 #nb of tweets
try:
# Pulling individual tweets from query
for tweet in api.user_timeline(id=username, count=count, include_rts = False):
# Adding to list that contains all tweets
tweets.append((tweet.text))
except BaseException as e:
print('failed on_status,',str(e))
time.sleep(3)
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是推文未完成,末尾带有“...”。
我想我已经查看了堆栈溢出和其他地方的所有其他类似问题,但没有任何效果。大多数人并不关心我,因为我不处理转发。
我尝试过将tweet_mode = 'extended'
and/or tweet.full_text
ortweet._json['extended_tweet']['full_text']
放在不同的组合中。
我没有收到错误消息,但没有任何效果,只是返回一个空列表。而且看起来文档已经过时了,因为它没有提到“tweet_mode”和“include_rts”参数:
有人设法获得每条推文的全文吗?我真的被这个看似简单的问题困扰并且正在掉头发,所以我将不胜感激任何建议:D 提前致谢!