最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】用Python的Playwright定位并点击百度搜索输入框

搜索 crifan 1983浏览 0评论
折腾:
【未解决】Mac中用playwright自动操作浏览器实现百度搜索
期间,去用Python版Playwright去实现百度首页的,搜索输入框,的定位,和输入文字
定位到 搜索框
参考:
【整理】用Chrome或Chromium查看百度首页中各元素的html源码
可以用Selector:
input#kw.s_ipt
想要去:点击搜索框 输入框
参考
microsoft/playwright-python: Python version of the Playwright testing and automation library. (github.com)
貌似直接可以click
page.click("text=Your location")
去试试
不过还是不会写定位输入框的语法
去找
playwright select element
Element selectors | Playwright 中文文档 | Playwright 中文网 (bootcss.com)
await page.click('text=Log in');
不区分大小写,支持部分文字(sub string)的匹配
await page.click(‘text="Login"');
带双(或单)引号就是 严格匹配了
text=Login
也支持:
<input type=button value="Login">
CSS选择器:
await page.click('button');
去写试试
    SearchInputSelector = "input#kw.s_ipt"
    page.click(SearchInputSelector)
结果:
是可以点击到输入框的。
Selector engines | Playwright
[Feature] Resolve <select> element based on label text · Issue #4400 · microsoft/playwright (github.com)
Element selectors | Playwright
【总结】
此处对于百度主页搜索输入框:
<input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
定位并点击的代码是:
    SearchInputSelector = "input#kw.s_ipt"
    page.click(SearchInputSelector)
后记:
对于从页面中寻找,定位,获取到,是元素类型的变量,则是:
详见:
【未解决】Python的Playwright去解析提取百度搜索的结果

转载请注明:在路上 » 【已解决】用Python的Playwright定位并点击百度搜索输入框

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
80 queries in 0.178 seconds, using 22.11MB memory