简体   繁体   English

如何在浏览器中显示python输出通过javascript?

[英]How to display in browser python output trough javascript?

Thanks to this script: 由于此脚本:

import requests
from bs4 import BeautifulSoup
import urllib2
import sys  
import urlparse
import io

url = "anUrl"
r = requests.get(url)
soup = BeautifulSoup(r.text,'lxml')
div = soup.find('div',id='content')
print div.prettify().encode(sys.stdout.encoding, 'ignore')

i've scraped some content that i want to print into another html page, trough javascript how can i handle the python output? 我已经将一些要打印的内容刮到另一个HTML页面中,通过javascript我如何处理python输出? Is it possible to print the content in the same way i've done in command line, with a browser page? 是否可以通过浏览器页面以与在命令行中相同的方式打印内容? I've got some encoding problems trying to do that. 我在尝试编码时遇到了一些编码问题。

If you are trying to write the div to an HTML file, then you basically do just that. 如果您试图将div写入HTML文件,那么基本上就是这样做。

f = open('file.html', 'w')
f.write(div)
f.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM