【发布时间】:2012-01-06 22:34:13
【问题描述】:
我有一个简单的需求:我希望使用 Beautiful Soup 将属性插入到 HTML 部分中,该属性会反映到网页中。
例如,对于 HTML 代码:
<input type="submit" name="name1">
我有 BeautifulSoup:
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup('<input type="submit" name="name1">')
getElementByName = soup.find(attrs={'name':'name1'})
# getElementByName.insert method does not reflect the insertion on the webpage
我希望为 Beautiful Soup 模仿以下 Javascript 方法:
document.getElementByName("name1").setAttribute("id", "id1");
我相信 Beautiful Soup 不能做到这一点,因为它只是一个 XML/HTML 解析器。但是,如果有人知道答案,那就把它扔在那里?
谢谢, 阿米特
【问题讨论】:
标签: python beautifulsoup