0

I am a beginner at phyton,i\ve been using it as a proxy to my retrocomputing hobby.

tghw has done this code ( https://github.com/tghw/macproxy) that filters everything but the links so that it can be opened in Macintosh classic. I wanna adapt it to windows 3.1, how can I add a beautiful soup tag that won't filter images?

thank you in advance

from bs4 import BeautifulSoup

def macify(html):
    soup = BeautifulSoup(html)
    for tag in soup(['script', 'link', 'style', 'noscript']):
        tag.extract()
    for tag in soup(['div', 'span']):
        tag.replaceWithChildren()
    for tag in soup():
        for attr in ['style', 'onclick',]:
            del tag[attr]
    return str(soup)

if __name__ == '__main__':
    import requests
    html = requests.get('http://stackoverflow.com/questions/5598524/can-i-remove-script-tags-with-beautifulsoup').content
    html = macify(html)
    with open('macified.html', 'w') as fd:
        fd.write(html)

0 Answers0