我想學習使用python的數據刮擦,並已使用Requests和BeautifulSoup4庫。它適用於普通的html網站。但是當我試圖從延遲數據加載的網站中獲取一些數據時,我發現我得到了一個空值。一個例子是僅在使用Python請求延遲數據加載後才能刮取html?
from bs4 import BeautifulSoup
from operator import itemgetter
from selenium import webdriver
url = "https://www.example.com/;1"
browser = webdriver.PhantomJS()
browser.get(url)
html = browser.page_source
soup = BeautifulSoup(html, 'lxml')
a = soup.find('span', 'buy')
print(a)
我想從這裏搶: (值)
我已經提到過類似的話題,並試圖類似的路線這裏提供的解決方案執行我的代碼。但不知何故,似乎沒有工作。我是新手,所以需要幫助完成這項工作。 How to scrape html table only after data loads using Python Requests?
該表(內容)可能是由JavaScript生成的,因此無法「看到」。我正在使用python3.6/PhantomJS/Selenium,這裏提供了很多答案。
你可以使用一些這http://selenium-python.readthedocs.io/waits.html或只加'time.sleep(N)' – AndMar
可以請你檢查網址?看來;有一個錯字,並可能導致您的刮板 – jabargas
@AndMar time.sleep錯誤似乎在這種情況下工作。請建議您建議我在哪裏添加? – fazal