在Colab中抓取动态内容-不起作用

时间:2020-11-06 08:30:46

标签: python-3.x google-colaboratory

我正在尝试从评论部分抓取一些数据,其中评论以树形结构组织,必须单击“展开”链接才能查看这些评论: 我的代码如下:

from selenium import webdriver
from selenium.common import exceptions
from time import sleep
from selenium.webdriver.common.keys import Keys
import os

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver', options=options)
url = ['https://******.livejournal.com ']
driver.get(url)
sleep(5)
links = driver.find_elements_by_link_text('Expand')
print(len(links))
for link in links:
  print('Expanding comment!')
  try:
    driver.execute_script("arguments[0].click();", link)
  except exceptions.StaleElementReferenceException as e:
    print(e)
print(driver.page_source)

此代码不会打印“扩展注释”,但是,在打印的page_source中我看不到这些注释

0 个答案:

没有答案