简体   繁体   English

单击 web 页面上的按钮(python,网络抓取)

[英]Click button on web page (python, webscraping)

I have a problem with clicking the button while scraping.我在抓取时单击按钮时遇到问题。 For example on the web page https://kolesa.kz/a/show/95457776 there is a button to show phone number (" Контакты продавца "), just on the right side of +7 777例如在 web 页面https://kolesa.kz/a/show/95457776上有一个显示电话号码的按钮(“ Контакты продавца ”),就在 +7 777 的右侧

I tried using method.click() of bs4 and I used div class of this button (" offer__show-phone action-link showPhonesLink js__show-phones ").我尝试使用bs4 的 method.click()并使用此按钮的 div class(“ offer__show-phone action-link showPhonesLink js__show-phones ”)。 But every time I got error that there is no such class name.但每次我都得到错误,没有这样的 class 名称。

Maybe you know other methods of it?也许你知道它的其他方法?

Thank you in advance!先感谢您!

The issue occurs where you're trying to locate an element using multiple classes, this causes selenium to throw back an error, the below will locate and click the button:问题发生在您尝试使用多个类定位元素时,这会导致 selenium 返回错误,下面将定位并单击按钮:

from selenium import webdriver

driver = webdriver.Firefox(executable_path = 'path_to_webdriver')
driver.get('https://kolesa.kz/a/show/95457776')

element = driver.find_element_by_class_name('showPhonesLink')

element.click()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM