Lurker News

Comments (41) 10 threads

Show all comments

Showing thread 3 of 10

createdjustnow1 reply#
Just in case if you thinking to download these links

import re import requests
from bs4 import BeautifulSoup
def download_file(download_url, name): #create response object r = requests.get(download_url, stream = True)

    #download started
    with open("repo" + name, 'wb') as f:
        for chunk in r.iter_content(chunk_size = 1024*1024):
            if chunk:
                f.write(chunk)

html = requests.get("<a href="https://getpolarized.io/2019/01/08/top-pdfs-of-2018-hackernews.html"" rel="nofollow">https://getpolarized.io/2019/01/08/top-pdfs-of-2018-hackerne...</a>) soup = BeautifulSoup(html.content) sAll = soup.findAll("a")<p>for href in sAll: if(href.has_attr('href')): link = href['href'] if(link.find(".pdf") > 0): print(link) last_index = link.rindex("/") name = link[last_index + 1:] print(name) try: download_file(link, name) except: print("error downloading " + link )
diminoten#

    from __future__ import print_function

    import re
    import requests

    from bs4 import BeautifulSoup

    def download_file(download_url, name):
        r = requests.get(download_url, stream = True)

        with open("repo" + name, 'wb') as f:
            for chunk in r.iter_content(chunk_size = 1024*1024):
                if chunk:
                    f.write(chunk)

    html = requests.get("https://getpolarized.io/2019/01/08/top-pdfs-of-2018-hackernews.html")
    soup = BeautifulSoup(html.content, features='html.parser')
    sAll = soup.findAll("a")

    for href in sAll:
        if href.has_attr('href'):
            link = href['href']
            if link.find(".pdf") > 0:
                print(link)

                last_index = link.rindex("/")
                name = link[last_index + 1:]
                print(name)

                try:
                    download_file(link, name)
                except:
                    print("error downloading " + link )