import requests
from lxml import etree
def main():
url = 'https://maoyan.com/board'
headers = {'user-agent': 'firefox'}
r = requests.get(url, headers=headers)
html = etree.HTML(r.text)
dds = html.xpath('//dd')
for dd in dds:
m_i = dd.xpath('./i/text()')[0]
m_name = dd.xpath('./a/@title')[0]
m_star = dd.xpath('normalize-space(./div[1]/div[1]/div[1]/p[2]/text())')[0]
m_releasetime = dd.xpath('./div[1]/div[1]/div[1]/p[3]/text()')[0]
print(m_i, m_name, m_star, m_releasetime)
if __name__ == '__main__':
main()
|