Launch HTML code in browser (that is generated by BeautifulSoup) straight from Python

后端 未结 3 665
情深已故
情深已故 2020-12-09 16:16

I have used BeautifulSoup for Python 3.3 to successfully pull desired info from a web page. I have also used BeautifulSoup to generate new HTML code to display this info. Cu

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 16:29

    (this grew enough I figured I should split it off as a separate answer:)

    As @reptilicus points out, you can use the built-in http.server module as follows:

    1. Create a web file directory and save your .html file in it.

    2. Open a command-line window and do

      cd /my/web/directory
      python -m http.server 8000
      
    3. Point your browser at http://127.0.0.1:8000

    This only works for static files; it will not run your script and return the results (as Flask does).

提交回复
热议问题