if res.status_code==200:
response=res.content.decode(“utf-8”)
return response
else:
return False
except:
return False
def parse_data(html,url):
#数据解析一些内容有的需要xpath 有的需要正则
html = etree.HTML(html)
headers = {
‘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’)
#导演,使用正则