我试图从一个网站上删除一些数据,实际上我可以得到它们,但它们是用两个不同的字符串编写的,就像在我的.csv中:
aaa
bbb
ccc
另一个:
^{pr2}$我想按以下格式写:
^{3}$以下是我目前为止编写的代码:
# import libraries
import urllib2
from bs4 import BeautifulSoup
import csv
i =0
# specify the url
quote_page = 'http://www.alertepollens.org/gardens/garden/1/state/'
# query the website and return the html to the variable 'page'
response = urllib2.urlopen(quote_page)
# parse the html using beautiful soap and store in variable `soup`
soup = BeautifulSoup(response, 'html.parser')
test = soup
with open('allergene.csv', 'w') as csv_file:
writer = csv.writer(csv_file)
pollene = (("".join(soup.strings)[65:]).encode('utf-8')).replace(' ','').replace('\n',' ').replace(' ',' ').replace(' ',' ').replace(' ','\n')
print pollene
state = (([img['alt'] for img in soup.find_all('img', alt=True)])).
print state.encode
polen = ''.join(pollene)
for item in state:
writer.writerow([item])
for item2 in pollene:
writer.writerow([item2])
其中一个主要问题是我有法语字符(é,ù,á等等),使用“strip()”不能正确显示这些字符。在
你知道我怎么做吗?在
输出:
^{pr2}$a.csv
是第一个csv文件,x.csv
是第二个csv文件,out.csv
是输出文件。在相关问题 更多 >
编程相关推荐