Python 模块“twill”——变量赋值期间的 HTML 泛滥
我正在制作一个简单的命令行程序,用于使用 Python 中的 Twill 模块从网站(非常通用)收集和解析信息。我想使用 Twill 的 show() 命令将 HTML 输出分配给一个变量,以通过我的解析命令运行页面,但每次我将它分配给一个变量时...
htmlString = twill.commands.show()
我都会在命令行上看到大量 HTML(和空闲,就此而言)。这是为什么呢?我不是要求打印变量,它附近没有打印命令。我只是想分配以进行进一步的操作。为什么变量赋值会导致打印发生?这不是一个致命的错误或什么的,只是非常非常不方便。我使用的是 Python 2.6、Twill 0.9 和 Ubuntu(如果有的话)。
I'm making a simple command line program for gathering and parsing information from websites (pretty generic) using the Twill module in Python. I want to assign the HTML output to a variable using Twill's show() command to run the page through my parsing commands, but every time I assign it to a variable...
htmlString = twill.commands.show()
I get a humongous flood of HTML on to the command line (and IDLE, for that matter). Why is this? I'm not asking to print the variable, there's no print command anywhere near it. I just want to assign in for further manipulation. Why would a variable assignment cause a print to occur? It's not a fatal error or anything, just really, really inconvenient. I'm on Python 2.6, Twill 0.9, and Ubuntu, if that pertains to anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用
lxml
或BeautifulSoup
来解析HTML,从未遇到过twill
。但是我看到你调用了.show()
方法,也许这个方法里面有print
语句。I would propose to use
lxml
orBeautifulSoup
to parse HTML, never facedtwill
. But I see you calling.show()
method, maybe this method haveprint
statement inside.Twill 是一种奇怪的东西,它会向终端打印大量输出。导致打印出内容的不是变量赋值,而是
show()
方法。它将打印(而不是返回)输出。Twill is an odd one and prints a lot of output to the terminal. It's not the variable assignment that's causing the stuff to be printed out, it's the
show()
method. It will print (rather than return) the output.