xpath help

Hi,

 

I am working on making a channel for a website that uses the Brightcove service. I need to get the values of the vars playerID, playerKey, and @videoPlayer. I have no problem getting playerID and playerKey, but @videoPlayer throws an error. If I hardcode the expected value, I get no error and everything is fine. So I assume it is something to do with the @ symbol. Does anyone have any suggestions to work around this?

###################################################################################################
@route(PREFIX + '/showdocs')
def ShowDocs(title, pass_url):

    #documentary level
    oc = ObjectContainer(title2=title)
    docElement = HTML.ElementFromURL(pass_url)
    docTitle = docElement.xpath(’//h1[@class=“title”]’)[0].text
    docSummary = docElement.xpath(’//head//meta[@property=“og:description”]’)[0].get(‘content’)
    #VideoID = ‘2252754546001’
    VideoID = docElement.xpath(’//param[contains(@name, “@videoPlayer”)]’)[0].get(‘value’)
    PlayerID = docElement.xpath(’//param[contains(@name, “playerID”)]’)[0].get(‘value’)
    PlayerKey = docElement.xpath(’//param[contains(@name, “playerKey”)]’)[0].get(‘value’)
    vidURL = ‘http://c.brightcove.com/services/viewer/federated_f9?isVid=1&isUI=1&videoId=’+VideoID+’&playerID=’+PlayerID+’&playerKey=’+PlayerKey+’&domain=embed&dynamicStreaming=true

    #menu level
    oc.add(VideoClipObject(title = docTitle, url = vidURL, summary = docSummary))
    return oc

- HTML/Javascript snippet from webpage

 

document.write('');
document.write('');
document.write('');
document.write('');
document.write('');
document.write('');
document.write('');

Seems like you’re trying to use xpath on HTML which is loaded dynamically via javascript when the page loads. That won’t work since the channel framework won’t execute the javascript. Since the javascript is actually contained in the page source, you can parse it as text using regex instead.


RE_VIDEOPLAYER = Regex(’’)


data = HTTP.Request(page_url).content
player = RE_VIDEOPLAYER.search(data).group(1)

Thank you Mikedm139! That did the trick. Would you recommend that I use regex on the other 2 vars as well even though I am able to use xpath to get their values? Does it matter? 

I probably doesn’t matter.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.