小编ale*_*scp的帖子

lxml.html.读取文件时出错; 无法加载外部实体

我正试图通过使用lxml.html进行解析来获取YouTube上的电影预告片:

from lxml import html
import lxml.html
from lxml.etree import XPath

def get_youtube_trailer(selected_movie):
# Create the url for the YouTube query in order to find the movie trailer
title = selected_movie
t = {'search_query' : title + ' movie trailer'}
query_youtube = urllib.urlencode(t)
search_url_youtube = 'https://www.youtube.com/results?' + query_youtube

# Define the XPath for the YouTube movie trailer link
movie_trailer_xpath = XPath('//ol[@class="item-section"]/li[1]/div/div/div[2]/h3/a/@href')

# Parse the YouTube html code
html = lxml.html.parse(search_url_youtube)

# Add the movie trailer to our results
results['movie_trailer'] = …
Run Code Online (Sandbox Code Playgroud)

parsing lxml lxml.html

4
推荐指数
1
解决办法
4671
查看次数

标签 统计

lxml ×1

lxml.html ×1

parsing ×1