0
我想用selenium和python刮一个网站。不过,我需要点击一个按钮来显示所需的信息。当按钮点击并且我接受时,网站会减少我的帐户点数。我只是想用硒自动化这个过程并且刮掉这个网站。我对蟒蛇和硒都很陌生。任何人都可以帮助我如何点击这样的按钮或执行脚本?Javascript void(0)点击或执行使用硒python
我当前的代码是:
driver.find_elements_by_xpath("//*[@id='show_info_button']")
它不返回任何错误,该按钮只是没有点击。我也尝试过driver.execute_script。但我不知道我试图执行的函数名称是什么,所以我发布了下面的按钮的HTML。
这里是按钮的HTML:
<a href="javascript:void(0);" id="show_info_button" class="btn btn-big btn-danger text-center">Xem thông tin ứng viên</a>
<script type="text/javascript">
$(document).ready(function() {
$process = false;
$('#show_info_button').click(function() {
if (!$process) {
$process = true;
$.ajax({
url: 'https://www.timviecnhanh.com/ho-so-show-info-point/ajax',
type: 'GET',
dataType : 'json',
data: {
employer_id: '2677857',
resume_id: '4065839',
package: '100',
remain_point: '611',
remain_point_gift: '0',
resume_point: '2'
},
async: false,
success: function(response) {
if (typeof response != 'undefined') {
$('#remain_point').text(parseInt($("#remain_point").text(), 10) - parseInt($("#resume_point").text(), 10));
$('#show_info_point').html(response.info);
$('#show_info_point_hide').hide();
if (typeof response.dinhkem != 'undefined') {
$('#preview-attach').html(response.dinhkem);
$('#preview-attach-resume-meta').hide();
$dinhkem_base64 = response.dinhkem_base64;
}
$('#show_info_button').hide();
$('#send_mail').append("<a href='https://www.timviecnhanh.com/nha-tuyen-dung/lien-he-nguoi-tim-viec?id=4065839&job_id=&last_cache_name=' class='btn btn-primary btn-send-mail'>Gửi mail</a>");
$('#send_mail_contact').append("<a href='https://www.timviecnhanh.com/nha-tuyen-dung/lien-he-nguoi-tim-viec?id=4065839&job_id=&last_cache_name=' class='btn btn-primary btn-send-mail'>Gửi mail liên hệ</a>");
$('#btn_view_attach').hide();
} else {
alert('Lỗi, refresh lại trình duyệt.');
}
}
}).done(function() {
// $process = false;
});
}
});
});
</script>
$(document).ready(function() {
$process = false;
$('#show_info_button').click(function() {
if (!$process) {
$process = true;
$.ajax({
url: 'https://www.timviecnhanh.com/ho-so-show-info-point/ajax',
type: 'GET',
dataType : 'json',
data: {
employer_id: '2677857',
resume_id: '4065839',
package: '100',
remain_point: '611',
remain_point_gift: '0',
resume_point: '2'
},
async: false,
success: function(response) {
if (typeof response != 'undefined') {
$('#remain_point').text(parseInt($("#remain_point").text(), 10) - parseInt($("#resume_point").text(), 10));
$('#show_info_point').html(response.info);
$('#show_info_point_hide').hide();
if (typeof response.dinhkem != 'undefined') {
$('#preview-attach').html(response.dinhkem);
$('#preview-attach-resume-meta').hide();
$dinhkem_base64 = response.dinhkem_base64;
}
$('#show_info_button').hide();
$('#send_mail').append("<a href='https://www.timviecnhanh.com/nha-tuyen-dung/lien-he-nguoi-tim-viec?id=4065839&job_id=&last_cache_name=' class='btn btn-primary btn-send-mail'>Gửi mail</a>");
$('#send_mail_contact').append("<a href='https://www.timviecnhanh.com/nha-tuyen-dung/lien-he-nguoi-tim-viec?id=4065839&job_id=&last_cache_name=' class='btn btn-primary btn-send-mail'>Gửi mail liên hệ</a>");
$('#btn_view_attach').hide();
} else {
alert('Lỗi, refresh lại trình duyệt.');
}
}
}).done(function() {
// $process = false;
});
}
});
});
感谢罗里,我是新来的Stackoverflow:D。 –
您的代码是否行得通? xpath看起来很好,而不是find_elements,使用find_element_by_xpath –
它不会返回错误,但按钮没有被点击。我也重试了你的代码,它返回了这个错误:find_element_by_xpath return self.find_element(by = By.XPATH,value = xpath) –