from selenium import webdriver
chromepath = "F:\_Python\Anaconda\chromedriver\chromedriver_win32\chromedriver"
driver = webdriver.Chrome(chromepath)
driver.get("https://item.jd.com/4161503.html")
comment = driver.find_element_by_css_selector('div.reply-content')
content = eachcomment.find_element_by_tag_name('p')
print(content.text)
以上是原始碼
報錯是:NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"div.comment-column.J-comment-column"}
(Session info: chrome=57.0.2987.133)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64)
對網頁檢查

<div id="comment-0" data-tab="item">........</div>這對標簽內有內容
但運行driver.page_source時
看到<div id="comment-0" data-tab="item">全部評論</div>\n
希望大家幫幫忙
uj5u.com熱心網友回復:
用selenium?速度很慢的uj5u.com熱心網友回復:
評論部分的內容一開始加載頁面的時候是不顯示的,需要你滾動到最底下才會加載,driver.execute_script('scrollBy(0,100000)')可以解決讓它滾到底部加載出評論內容。不過你要找的標簽你自己再檢查下有沒有。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/72018.html
上一篇:jupyter notebook中如何將已markdown型別的字體更改大小或者變成黑體字?
下一篇:極大似然小結
