javascript - 如何通过 Python Selenium 更改网页源代码?
问题描述
我想制作将 pdf 文件嵌入到 chrome 中查看页面上的表格中的代码。理想情况下通过 Selenium Webdriver。这意味着我需要更改页面上的 html 代码
<td align="center"> </td>
至
<embed src="http://qwer.com/a.pdf" type = "application/pdf">
现在我明白了你可以通过 driver.execute_script 启动 JavaScript,但是之前没有使用 JavaScript 的经验,我被卡住了。
据我所知,这是:
driver.execute_script("""document.evaluate('/html/body/div[9]/form/table/tbody/tr[10]/td[3]', document, null, XPathResult.ANY_TYPE, null).align="right";""")
该脚本尝试通过 XPath 选择 html 表格中的单元格并进行微小更改 - 对齐。它失败了。
我也一直在尝试更戏剧化的事情,但随着时间的推移,我什至无法弄清楚这个简单的事情,我恳求帮助。
感谢任何有建设性批评的人!
解决方案
推荐阅读
- html - 一个块元素将另一个块元素推离屏幕
- java - 将 GCP RecognizeResponse 转换为 json
- reactjs - 向嵌套的解构道具添加类型。Typescript React Redux。TS2339
- algorithm - 使用“路径减半”对不相交集进行 Find() 操作
- javascript - 在 React Native 中将变量从一个文件传递到另一个文件
- c# - Prism DelegateCommand 未在 SelectionChanged 上触发
- powershell - 带有 Selenium 的 Powershell:我无法让“滚动视图”工作
- ag-grid - Ag-Grid 行数据 .map param.value
- python-3.x - 如何从 Mac 上的默认预安装 Python 2.7 转移到终端中从 Anaconda 访问 Python 3.7?
- string - 使用 sed 从配置文件中提取某些字符串