Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在我的文本中不断出现一些空白_Python_Csv_Export To Csv - Fatal编程技术网

Python 在我的文本中不断出现一些空白

Python 在我的文本中不断出现一些空白,python,csv,export-to-csv,Python,Csv,Export To Csv,任何人都知道如何消除这些空白的刮文本,因为这使它真的很难存储在csv文件。html在“username”类中有很多空白,如下图所示 使用 删除空白 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

任何人都知道如何消除这些空白的刮文本,因为这使它真的很难存储在csv文件。html在“username”类中有很多空白,如下图所示

使用

删除空白

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()  
username.get_text().strip()