|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
[code]import requests
from lxml import etree
#将目标页面抓取下来
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400',
'Referer': 'https://movie.douban.com/'}
url = 'https://movie.douban.com/'
response = requests.get(url,headers= headers)
text= response.text
#将抓取下来的数据进行一定规则的提取
html = etree.HTML(text)
ul = html.xpath("//ul[@class='lists']")[0]
lis = ul.xpath("./li")
for li in lis:
title = li.xpath('@data-title')[0]
actors = li.xpath('@data-actors')[0]
movies =[]
movie = {
'title':title,
'actors':actors
}
movies.append(movie)
出现
Traceback (most recent call last):
File "C:/Users/lenovo/PycharmProjects/SCRAPY/DAY3/豆瓣250/main.py", line 13, in <module>
ul = html.xpath("//ul[@class='lists']")[0]
IndexError: list index out of range |
|