上传从网站抓取的文件到 ftp 服务
upload files that craw from website to ftp serve
我正在做一个爬虫程序。
我制作了从网页抓取新闻的爬虫,它可以上传到我的本地计算机,但是
我想直接上传到FTP服务器。
我尝试以不同的方式编写代码。但我不能...
我的代码如下
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))
我使用 BytesIO 解决了这个问题
我的代码在 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)
我正在做一个爬虫程序。 我制作了从网页抓取新闻的爬虫,它可以上传到我的本地计算机,但是 我想直接上传到FTP服务器。
我尝试以不同的方式编写代码。但我不能...
我的代码如下 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))
我使用 BytesIO 解决了这个问题 我的代码在 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)