我如何点击urllib2

时间:2016-06-14 07:16:17

标签: python python-2.7 python-3.x urllib2 urllib

这是一个文本框,我想知道是否可以点击它

<input type="text" id="FirstName" class="form-control" name="FirstName" data-bind="inputWithPlaceholder: firstName, value: firstName, css: { 'has-error': showError(firstName) }, hasFocus: firstName.focused, tooltip: { target: '#LastName' }">

2 个答案:

答案 0 :(得分:1)

目前尚不清楚你想要什么。

1)如果您只想获取文本/标签,请使用lxml库

from lxml import html

page = requests.get('http://econpy.pythonanywhere.com/ex/001.html') 
# or just get the page using urllib2 library 
tree = html.fromstring(page.content)
buyers = tree.xpath('//div[@title="buyer-name"]/text()')
print buyers

在你的情况下,它会像tree.xpath('//input[@id="FirstName"]')

2)如果您想运行浏览器,请单击您需要使用 selenium

的按钮(模拟用户的操作)

答案 1 :(得分:0)

我建议selenium它在开始时有点棘手但是因为它打开了一个webb浏览器,所以很容易就能发现正在发生的事情。

(当你按名称,id,类等找到你的元素时,你只需要编写element.click())