帮助解析 HTML 并将请求发送到 Web 服务器
我正在做一个小项目,遇到了一个小问题。我的脚本需要获取网站并在源 HTML 文件中查找特定值。值是这样的:
id='elementID'>
<fieldset>
<input type='hidden' name='hash' value='e46c945fe32a3' />
</fieldset>
现在我一直在尝试使用 ElementTree 库来解析 HTML 文档以找到该值,但我还没有很成功。我对 Python 很陌生,所以我真的不知道下一步该做什么。
我一直在使用 httplib 和 urllib/urllib2 连接到网站并发布我的登录详细信息和类似的内容,但我真的不知道如何从页面获取该值。我以为我可以发送一个名为“hash”的输入请求,但我不知道该怎么做。
I'm working on a small project and I've run into a small problem. The script I have needs to fetch a website and find a specific value in the source HTML file. The value is like this:
id='elementID'>
<fieldset>
<input type='hidden' name='hash' value='e46c945fe32a3' />
</fieldset>
Now I'm been trying to use the ElementTree library to parse the HTML document to find the value but I haven't been very successful. I'm really new to Python so I don't really know what to do next.
I've been using httplib and urllib/urllib2 to connect to the website and POST my login details and things like that but I really don't know how to get that value from the page. I thought I could send a request for the input named 'hash' but I have no idea how to do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以考虑查看 BeautifulSoup 库 - 它的设计快速且易于使用。
You might consider looking at the BeautifulSoup library - it's designed to be quick and easy to use.