簡體   English   中英

Python AttributeError:“ str”對象沒有屬性“ get”

[英]Python AttributeError: 'str' object has no attribute 'get'

我想抓取一個網站。

但是,發生錯誤。

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'

流程以退出代碼1完成

如何解決此錯誤?

感謝您的意見。

#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()

看起來您有錯別字:

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

我不認為等號應該存在。

用新鮮的水蟒環境進行了測試。 在安裝phantomjs之前,我遇到了同樣的錯誤。 到那時為止,看起來好像python只是事物驅動程序是一個字符串變量,而不是具有get方法的特殊對象。

如果您不使用anaconda,則這里有一個幻像頁面http://phantomjs.org/download.html

如果您使用anaconda,請按照此處的說明進行操作https://anaconda.org/trent/phantomjs

讓我知道這是否適合您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM