我想从url链接后面的某一行添加链接,该链接是一个.txt文件,包含类似于以下内容的内容:
X-Y-Z
3 -- 5-1
6 -- 4-2
7-2-3
等等..。我只设法让它读取所有的文件并将它们附加到一个新的文件中,但是我想省略第一行。
import urllib.request as ur
import shutil
with ur.urlopen(#link) as link, open("#filePath", 'ab') as Data:
shutil.copyfileobj(link, Data)有没有一种方法可以分割url中的行以附加到新文件中?
发布于 2021-05-11 19:39:36
只需显式跳过第一行:
import urllib.request as ur
import shutil
with ur.urlopen(#link) as link, open("#filePath", 'ab') as Data:
link.readline() # Reads one line, discards it, leaves link positioned after it
# next(link, None) should also work; there are subtle differences,
# but either should work here
shutil.copyfileobj(link, Data)https://stackoverflow.com/questions/67493303
复制相似问题