【发布时间】:2019-05-29 19:36:54
【问题描述】:
我正在尝试使用 selenium 或 scrapy 从这个特定的 url 中刮取一些数据。
我已经毫无问题地抓取了其他页面,但是当涉及到这些特定的 url 时,我试图抓取到列表中的信息返回为空。我使用了scrapy,然后继续使用硒,但结果是一样的。我也在使用 pycharm 和 chromedriver。
我特别要查找的信息是“https://shop.freedommobile.ca/devices”上的所有不同手机型号。我打印列表只是为了发现没有从网站上抓取任何内容,或者抓取成功但没有返回任何内容。
当我尝试从这里抓取任何东西时也会发生同样的情况:
from selenium import webdriver
#open chrome browser and navigate to the webpage
driver = webdriver.Chrome()
driver.get("https://shop.freedommobile.ca/devices")
#extract the names of the phones
phones = driver.find_elements_by_css_selector('.jXeFbj')
#counts phone and its model
for element in range(len(phones)):
numPhone = int(element) + 1
print("phone "+ str(numPhone) +" : " + phones[element].text)
#number of phones in total
sizeOfList = len(phones)
print(sizeOfList)
应该发生的事情是将手机的所有型号名称拉到一个列表中。
手机 = ['iPhone XS Max', 'iPhone XS', 'iPhone XR',...]
【问题讨论】:
-
尝试添加 EC 以便脚本等待项目加载。
WebDriverWait(driver,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,".jXeFbj"))).
标签: python-3.x selenium web-scraping scrapy css-selectors