koko
koko

Reputation: 177

Python AttributeError: 'str' object has no attribute 'get'

I want to crawl a website.

However, an error occurred.

C:\Users\xxx\AppData\Local\Programs\Python\Python36\python.exe C:/Users/xxx/Desktop/scrap.py
Traceback (most recent call last):
  File "C:/Users/xxx/Desktop/scrap.py", line 10, in <module>
    driver.get('https://www.powderroom.co.kr/rankings/c1100')
AttributeError: 'str' object has no attribute 'get'

Process finished with exit code 1

How do I resolve this error?

Thank you for your advice.

#py3.6,pycharm
import re
from bs4 import BeautifulSoup
from selenium import webdriver
import time

driver = webdriver.PhantomJS=("c:|phantomjs-2.1.1/windows/bin/phantomjs")

driver.get('https://www.powderroom.co.kr/rankings/c1100')
i = 0
while i < 8:
    i = i + 1
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(1)

bs = BeautifulSoup(driver.page_source, 'lxml')

titles = bs.findAll('div', attrs={'class':'fs-5 tc-gray-1'})
for title in titles:
    result = str(title.find_all(text=True))
    result = re.sub('[\{\}\[\]\/?.,;:|\)*~`!^\-_+<>@\#$%&\\\=\(\'\"]', '', result)
    print(result)
driver.quit()

Upvotes: 0

Views: 2556

Answers (2)

Shawn S
Shawn S

Reputation: 59

Did A test with fresh anaconda env. I got the same error until I installed phantomjs. Up until that point it looks like python just things driver is a string variable, not something special that has a get method.

if you're not using anaconda here is a like to phantoms page http://phantomjs.org/download.html

if your using anaconda just follow the instructions here https://anaconda.org/trent/phantomjs

Let me know if this works for you.

Upvotes: 0

Brionius
Brionius

Reputation: 14098

Looks like you have a typo:

driver = webdriver.PhantomJS=("c:|phantomjs-2.1.1/windows/bin/phantomjs")
                            ^

I don't think that equals sign is supposed to be there.

Upvotes: 4

Related Questions