‘User-Agent’: ‘Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36’
}
res = requests.get(url=url, headers=headers)
response = res.content.decode(“utf-8”)
#电影名称
movie_title=html.xpath(“//div[@class=‘hd’]//a//span[1]//text()”)
#电影评分
movie_score=html.xpath(‘//div[@class=“star”]//span[2]//text()’)
#电影排名
movie_degree=html.xpath(‘//div[@class=“item”]//div//em//text()’)
#电影海报地址
movie_poster=html.xpath(‘//div[@class=“pic”]//a//img/@src’)
#导演,使用正则
movie_director = re.findall(r"导演:(.*?);", response)
a = “”.join(movie_director).split(“ ”)#因为使用的正则抓取下来的字符串含有 ,使用split()函数进行切分
movie_director = a[:25]
if movie_director==“”:
movie_director=“”
else:
movie_director=