weixin_40650670
weixin_40650670
2017-11-23 11:38

python+selenium如何抓取diplay:none的标签内容?

10
  • python
  • selenium

图片说明
如图 我抓取到的页面里面由于这几个标签是displaynone 导致抓不到 代码如下
from selenium import webdriver
url = "http://t.shuqi.com/#!/ct/read/bid/6584515/cid/639384"
driver = webdriver.PhantomJS(executable_path='G:/phantomjs/bin/phantomjs.exe')
driver.get(url)
js = 'document.getElementsByClassName("read-body")[0].getElementsByTagName("div")[3].style.display="block";'
driver.execute_script(js)
contentText = driver.find_element_by_id('read_in').text

w = open('G:/python/pytxt/dynamic/1.txt','w')
w.write(contentText)
driver.quit()

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答