【发布时间】:2015-06-16 09:33:49
【问题描述】:
我正在尝试从此页面上的链接获取视频网址。视频链接可以在https://in.news.yahoo.com/video/jaguar-fighter-aircraft-crashes-near-084300217.html 上看到。 (在 Chrome 中打开)
为此,我编写了 chrome web driver 相关代码如下:
from bs4 import BeautifulSoup
from selenium import webdriver
from pyvirtualdisplay import Display
chromedriver = '/usr/local/bin/chromedriver'
os.environ['webdriver.chrome.driver'] = chromedriver
display = Display(visible=0, size=(800,600))
display.start()
driver = webdriver.Chrome(chromedriver)
driver.get('https://in.news.yahoo.com/video/jaguar-fighter-aircraft-crashes-near-084300217.html')
try:
element = WebDriverWait(driver, 20).until(lambda driver: driver.find_elements_by_class_name('yvp-main'))
self.yahoo_video_trend = []
for s in driver.find_elements_by_class_name('yvp-main'):
print "Processing link - ", item['link']
trend = item
print item['description']
trend['video_link'] = s.find_element_by_tag_name('video').get_attribute('src')
print
print s.find_element_by_tag_name('video').get_attribute('src')
self.yahoo_video_trend.append(trend)
except:
return
这在我的本地系统上运行良好,但是当我在我的 azure 服务器上运行时,它在 s.find_element_by_tag_name('video').get_attribute('src') 上没有给出任何结果
我已经在我的 azureserver 上安装了 chrome。
更新:
请看,requests 和 Beautifulsoup 我已经尝试过了,但是当 yahoo 从 json 动态加载 html 内容时,我无法使用它们。
是的,天蓝色服务器是具有命令行访问权限的简单 linux 系统。不是任何应用程序。
【问题讨论】:
标签: python azure selenium web-scraping