2017-01-20 6 views
0

誰もが廃棄されたテキストのこれらの隙間をなくす方法を知っています。 htmlには、以下の図に示すように、「username」クラスに多くのギャップがあります。私はテキストを取り去った後も何かの隙間を残しています

enter image description here

for i in range(0,2): 
    link = (df.link.iloc[i]) 
    source1 = urllib.request.urlopen(link).read() 
    soup1 = bs.BeautifulSoup(source1,'lxml') 
    for username in soup1.find_all('div', class_="user-name"): 
     print (username.get_text()) 
# for time in soup1.find_all('div',class_="thread-ago"): 

example = open('generalinfo.csv','w') 
wr = csv.writer(example,quoting = csv.QUOTE_ALL)   
wr.writerows(lists)  
example.close() 

答えて

0

空白を取り除くために

username.get_text().strip() 

を使用しています。

関連する問題