Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Python的selenium中访问专用页面?_Javascript_Python_Selenium_Xpath_Web Crawler - Fatal编程技术网

Javascript 如何在Python的selenium中访问专用页面?

Javascript 如何在Python的selenium中访问专用页面?,javascript,python,selenium,xpath,web-crawler,Javascript,Python,Selenium,Xpath,Web Crawler,目前我想转到网站的第123页: 很抱歉,它是中文的,但可能与这个问题无关 在本页的按钮中,我们可以看到1,2,3,。。。还有一个文本区域,我们可以点击文本区域,然后在文本区域中输入123。然后我们只需点击“开始”按钮,它就会转到第123页 我想用selenium在Python2.7中模拟这个过程。当我尝试将值123传递给文本区域时,我发现此输入文本区域没有名称或id。页面源的相关部分如下所示: <table border="0" cellspacing="0" cellpadding="0

目前我想转到网站的第123页: 很抱歉,它是中文的,但可能与这个问题无关

在本页的按钮中,我们可以看到1,2,3,。。。还有一个文本区域,我们可以点击文本区域,然后在文本区域中输入123。然后我们只需点击“开始”按钮,它就会转到第123页

我想用selenium在Python2.7中模拟这个过程。当我尝试将值123传递给文本区域时,我发现此输入文本区域没有名称或id。页面源的相关部分如下所示:

<table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr>
<td align="right" class="pager" valign="bottom" style="width:40%;overflow:hidden;">共12318页&nbsp;当前只显示200页&nbsp;共369525条记录</td>
<td align="left" class="pager" valign="bottom" style="width:60%"> 
<a disabled="disabled" style="margin-right:5px;">首页</a>
<a disabled="disabled" style="margin-right:5px;">上页</a>
<span style="color: red;font-weight: bold;margin-right: 5px;">1</span>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',2)" style="margin-right:5px;">2</a>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',3)" style="margin-right:5px;">3</a>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',4)" style="margin-right:5px;">4</a>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',5)" style="margin-right:5px;">5</a>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',6)" style="margin-right:5px;">6</a>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',7)" style="margin-right:5px;">7</a>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',8)" style="margin-right:5px;">8</a>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',9)" style="margin-right:5px;">9</a>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',10)" style="margin-right:5px;">10</a>
<span><a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',11)"style="margin-right:5px;">...</a></span>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',2)" style="margin-right:5px;">下页</a>
<a href="javascript:void(0)" onclick="QueryAction.GoPage('TAB',200)" style="margin-right:5px;">尾页</a>
<input type="text" style="width:30px;" value="1" onkeypress="if(event.keyCode==13)QueryAction.GoPage('TAB',this.value,200);"/>
<input type="button" value="go" onclick="QueryAction.GoPage('TAB',this.previousSibling.value,200)"/> 
</td></tr></tbody></table>

但是Chrome没有在文本区输入数字123,网站停留在第1页。有人知道如何处理这种情况吗?非常感谢。

一个选项是依靠go按钮,并使用@type='text'获取前面的第一个兄弟:

此外,作为发送_键选项的替代选项,您可以设置文本区域值:


它返回一个错误,表示xpath字符串包含无法解析的名称空间。您的脚本在该框中不起作用,但当我尝试在go按钮上使用类似的脚本时,它起作用。go=browser。通过xpath//input[@type='button']浏览器查找元素。执行脚本查询操作。GoPage'TAB','123',200,go
browser=webdriver.Chrome()
loc="http://www.landchina.com/default.aspx?tabid=351"
browser.get(loc)

box=browser.find_element_by_xpath("//input[@type='text']") # find the text area
box.click()
box.send_keys("123") # send 123 to the text area

go=browser.find_element_by_xpath("//input[@type='button']") # find the "GO" button
go.click()
content=browser.page_source
print content
//input[@type='button' and @value='go']/preceding-sibling::input[@type='text'] 
box = browser.find_element_by_xpath("//input[@type='button' and @value='go']/preceding-sibling::input[@type='text'] ")
driver.execute_script("arguments[0].value = '123'", box)