我正在制作一個(gè)爬蟲程序。我制作了從網(wǎng)頁(yè)抓取新聞的爬蟲,它可以上傳到我的本地計(jì)算機(jī),但我想直接上傳到 FTP 服務(wù)器。我嘗試以不同的方式編碼。但我不能...我的代碼在python下面for i in range(0,len(a),2): url = defaultInformation['gooktoHome'] + a[i].attrs['href'] r = requests.get( url, allow_redirects=True) fileName = datetime.now().strftime('%Y%m%d%H%M%S') # print(r.text) if(a[i].attrs['href'][-3:] == 'pdf'): ftp.storbinary('STOR ' + '/uh/backup/' + fileName + '.pdf',open(r.content))
1 回答

largeQ
TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊
我使用 BytesIO 解決了這個(gè)問(wèn)題我的代碼在 python 下面
for i in range(0,len(a),2):
url = defaultInformation['gooktoHome'] + a[i].attrs['href']
r = requests.get(
url, allow_redirects=True)
fileName = datetime.now().strftime('%Y%m%d%H%M%S')
if(a[i].attrs['href'][-3:] == 'pdf'):
tFile = BytesIO(r.content)
ftp.storbinary('STOR ' + '/uh/backup/' + fileName + '.pdf',tFile)
添加回答
舉報(bào)
0/150
提交
取消