使用 urllib 更改表的值
我正在尝试使用 urllib 更改表中的值。我相信做到这一点的方法是使用 post 请求。然而我没有取得任何成功并且完全迷失了。
感谢您可以分享的任何帮助。
这是我正在尝试编辑的页面(editme.php),
<html>
<body>
<div>
<table>
<tr>
<td id="changme">1</td>
</tr>
</table>
</div>
</body>
</html>
我正在本地运行,我想将单元格中的值更改为其他值。我正在尝试使用以下方法来做到这一点:
import urllib
import urllib2
from BeautifulSoup import BeautifulSoup
values = urllib.urlencode({'changeme' : 'i have changed'})
f = urllib.urlopen("http://localhost/editme.php",values)
readdata = urllib.urlopen("http://localhost/editme.php")
print BeautifulSoup(readdata).prettify()
I am trying to change the values in a table using urllib
. I believe the way to do this is by using post request. However I am having no success whatsoever and am completely lost.
Any help you can share is appreciated.
Here is the page I am trying to edit (editme.php)
<html>
<body>
<div>
<table>
<tr>
<td id="changme">1</td>
</tr>
</table>
</div>
</body>
</html>
I am running things locally and I want to change the value in cell w/ id="changeme"
to something else. I am trying to do that using this:
import urllib
import urllib2
from BeautifulSoup import BeautifulSoup
values = urllib.urlencode({'changeme' : 'i have changed'})
f = urllib.urlopen("http://localhost/editme.php",values)
readdata = urllib.urlopen("http://localhost/editme.php")
print BeautifulSoup(readdata).prettify()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你所问的没有任何意义。您必须更改模板或在服务器上呈现表格的任何内容,而不是通过下载/上传。
Does not make any sense what you are asking. You have to change the template or whatever is rendering your table on the SERVER and not through download/upload.
Em...抱歉,但是您无法通过 urllib 更改该表值,除非 php 脚本这样做。 editme.php 是一个“纯”html 文件。
Em... sorry, but there is no way you'll change that table value via urllib, unless the php script does that. And the editme.php is a "pure" html file.