小编Fil*_*uel的帖子

使用请求和BeautifulSoup下载文件

我正在尝试使用requestsbeautifulsoup4这里下载一堆pdf文件.这是我的代码:

import requests
from bs4 import BeautifulSoup as bs

_ANO = '2013/'
_MES = '01/'
_MATERIAS = 'matematica/'
_CONTEXT = 'wp-content/uploads/' + _ANO + _MES
_URL = 'http://www.desconversa.com.br/' + _MATERIAS + _CONTEXT

r = requests.get(_URL)
soup = bs(r.text)

for i, link in enumerate(soup.findAll('a')):
    _FULLURL = _URL + link.get('href')

    for x in range(i):
        output = open('file[%d].pdf' % x, 'wb')
        output.write(_FULLURL.read())
        output.close()
Run Code Online (Sandbox Code Playgroud)

我到了AttributeError: 'str' object has no attribute 'read'.

好的,我知道,但是...如何从生成的URL下载?

python download beautifulsoup python-requests

4
推荐指数
2
解决办法
2万
查看次数

Heroku创建了表格,但是当我迁移时,他说并没有创建表格

我在Heroku中制作了syncdb(Python / Django应用程序),他创建了一个表格south_migrationhistory,

(venv-project)username@username:~/projectapp$ heroku run python manage.py syncdb
Running `python manage.py syncdb` attached to terminal... up, run.5529
Syncing...
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table south_migrationhistory
Run Code Online (Sandbox Code Playgroud)

(...)

Synced:
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.messages
 > django.contrib.staticfiles
 > django.contrib.admin
 > south

Not synced (use migrations):
 - core
 - …
Run Code Online (Sandbox Code Playgroud)

deployment django heroku

3
推荐指数
1
解决办法
2761
查看次数

如何将类放在循环内的特定(第一个元素)上?

在 Twitter Bootstrap Carousel Slide 中,需要一个名为“active”的类来设置所有幻灯片首先使用哪个图像,然后初始化循环。但是,如果我的对象(我想在幻灯片中显示)处于循环中,我该如何设置这个类?

<div id="myCarousel" class="carousel slide img-polaroid">
  <div class="carousel-inner">

    {% for slide in slides_list %}
    <div class="item"> <!-- Here goes the class="active" -->
      <img src="{{slide.imagem.url}}" alt="{{slide.imagem.titulo}}" />
      <div class="carousel-caption slider">
        <h2>{{slide.titulo}}</h2>
        <p>{{slide.mensagem}}</p>
      </div><!--/carousel-caption-->
    </div><!--/item-->
    {% endfor %}

  </div><!--/carousel-inner-->

  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>

</div><!--/myCarousel-->
Run Code Online (Sandbox Code Playgroud)

提前致谢。

django twitter-bootstrap

2
推荐指数
1
解决办法
1184
查看次数

接收一个字符串,转换为计算并显示响应,但是..无法拆分

我的作业问题:

创建脚本以接收出生日期并返回用户的年龄

我试过这个:

ano_atual = 2012                                       
data_nascimento = input('Digite sua data de nascimento (dd/mm/aaaa): ')
dia, mes, ano = map(int, data_nascimento.split('/'))
idade = ano_atual - ano
print idade
Run Code Online (Sandbox Code Playgroud)

但是我遇到了这个错误:

AttributeError: 'int' object has no attribute 'split'
Run Code Online (Sandbox Code Playgroud)

python python-2.7

0
推荐指数
1
解决办法
719
查看次数