我刚刚尝试了前面一个类似于我的问题所建议的语法,但它对我不起作用。我试过:
newvar = str(oldvar)
newvar = newvar.replace('\r', '').replace('\n', ' ')
我试过:
newvar = oldvar.replace('\r', '').replace('\n', ' ')
我的完整(相关)代码部分如下:
URLS = myurls2.values()
# Retrieve a single page and report the url and contents
def load_url(key, url, timeout):
conn = urllib.request.urlopen(url, timeout=timeout)
return conn.readall()
# We can use a with statement to ensure threads are cleaned up promptly
with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor:
# Start the load operations and mark each future with its URL
future_to_url = {executor.submit(load_url, key, url, 60): (key, url)
for key, url in myurls2.items()}
c = 0
for future in concurrent.futures.as_completed(future_to_url):
key, url = future_to_url[future]
try:
data = str(future.result())
data2 = str(data)
data2 = data2.replace('\r', '').replace('\n', ' ')
print(data2)
d = open(filepath,"w")
d.write(data2)
d.close()
字典值被转换为URL,然后提交到相关网站,最后我希望将它们转换为字符串,并删除replace语句中列出的字符
谢谢
目前没有回答
相关问题 更多 >
编程相关推荐