Coder Social home page Coder Social logo

toutiao's Issues

在下载图片的时候,如何将图片存储到不同到目录(图片相对应到文章名称)下面。

自己在存储前加了一个目录判断,程序可以正常运行,但是下载图片结果是每篇文章只有一张图片被下载存储。代码如下:

def save_images(content, page, title):
    dir_path = '{0}/{1}/{2}/{3}'.format(os.getcwd(), 'images',page//20, title)
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)
        file_path = '{0}/{1}.{2}'.format(dir_path, md5(content).hexdigest(), 'jpg')
        if not os.path.exists(file_path):
            with open(file_path, 'wb') as f:
                f.write(content)
                f.close()

image
运行输出都显示已经下载:
image

求问,为什么照着您的教程敲得正则代码,在pycharm中要不就是一直运行没有结果,要不就是结果为空,我也对照了新的网页代码(猫眼电影和豆瓣),求教,是否是pycharm问题或者是什么?多谢了。

求问,为什么照着您的教程敲得正则代码,在pycharm中要不就是一直运行没有结果,要不就是结果为空,我也对照了新的网页代码(猫眼电影和豆瓣),求教,是否是pycharm问题或者是什么?多谢了。

在获取组图详情页的时候发生多次重定向

经过多次尝试使用requests请求详情页,发现最少发生一次重定向,最多三次,重定向路径为

[http://taobao.com/group/xxxxxxx -> http://www.taobao.com/group/xxxxxxx -> https://www.taobao.com/group/xxxxxx -> https://www.taobao.com/axxxxxxxx]

这种情况导致在获取html代码的时候无法获取到最终url的代码怎么解决?所以无法正常找到想要的内容

我自己是把从 article_url获取到的 url 中的 group/ 替换成 a 就能正常访问了。

url = 'http://toutiao.com/group/6444359581934141710/'
url = url.replace('group/', 'a')

代码修正后:cnsimo/toutiao

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.