Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selenium TypeError
#2
There is problem with your setup here @charset.
Find_Elements_By_Css_Selector it should not be capitalized,will give AttributeError.
Here is more modern way to set up,here use Firefox an these setup option may be required,
it can also depend on version of driver and Selenium which should be the newest.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
import time, random

#--| Setup
options = Options()
#options.add_argument("--headless")
caps = webdriver.DesiredCapabilities().FIREFOX
caps["marionette"] = True
browser = webdriver.Firefox(options=options, capabilities=caps, executable_path=r"geckodriver.exe")
#--| Parse or automation
rand_page = random.randint(1, 5)
url = f"https://eksisozluk.com/mustafa-kemal-ataturk--34712?p={rand_page}"
browser.get(url)
time.sleep(2)
content = browser.find_elements_by_css_selector('.content')
print(content)
Work in test,content will return a list of Selenium objects.
So it call .text on it,will see content.
>>> content[0].text
'(bkz: ubermensch)'
>>> content[1].text
'(bkz: deha)\n(bkz: dusunce)\n(bkz: gorus)\n(bkz: zeka)\n(bkz: basari)'
>>> content[2].text
("kutsal kehanetlerde adi gecen '19 yy da ortadogudan bir adam cikacak ve tum "
 "dunyaya kafa tutacak' dedigi , yuce insan, 4 kusak ileriyi gorebilen, esi "
 'bulunmaz bir yasam insani, arif, yol gosterici')
Reply


Messages In This Thread
Selenium TypeError - by charset - Feb-28-2020, 11:37 AM
RE: Selenium TypeError - by snippsat - Feb-28-2020, 01:42 PM
RE: Selenium TypeError - by snippsat - Feb-29-2020, 10:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,769 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020