Reputation:
I Want To Scrape Data From This Button How Can i Do Using Selenium Python
Here is the button screenshot:
Here is the website link: https://www.zameen.com/EstateAgents/Islamabad-3-152.html
Here is my code:
driver = webdriver.Chrome()
for i in range(1,154):
driver.get('https://www.zameen.com/EstateAgents/Islamabad-3-' + str(i) + '.html')
name = driver.find_elements_by_css_selector('#agent_search_listing_section .title')
number = driver.find_elements_by_css_selector('.totalofnum:nth-child(3)')
Total_Number =driver.find_elements_by_css_selector('.titanium-con+ .clearfix')
button = driver.find_elements_by_css_selector('#agent_phone').click()
time.sleep(3)
phone = driver.find_elements_by_css_selector('.phone_click')
items = len(name)
with open(csv,'a') as s:
for item in range(items):
s.write(name[item].text + ',' + number[item].text + ',' + Total_Number[item].text + ',' + phone[item].text + '\n')
I Want to scrape Data From Call Button but i get this error when i try?
error:
Traceback (most recent call last):
File "scrap.py", line 16, in <module>
button = driver.find_elements_by_css_selector('#agent_phone').click()
AttributeError: 'list' object has no attribute 'click'
Upvotes: 1
Views: 674
Reputation: 758
The thing is you're using find_elements_by_css_selector
, notice the elements
in there, thats why it returns a list & your error says 'list' object has no attribute 'click'
. So either use
button = driver.find_element_by_css_selector('#agent_phone').click()
or
button = driver.find_element_by_id('agent_phone').click()
Notice that we're using element
here instead of elements
Upvotes: 2