淘先锋技术网

首页 1 2 3 4 5 6 7
import requests
from bs4 import BeautifulSoup
import re


def gethtml():
    headers = {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'
    }
    url = "http://ent.sina.com.cn/movie/top10bang/?qq-pf-to=pcqq.c2c"

    response = requests.get(url=url, headers=headers)
    response.encoding = "utf-8"
    html = response.text
    # print(html)
    soup = BeautifulSoup(html, 'lxml')
    # soup.find_all()
    riqi = soup.find('span', class_='time_range').text
    print("日期:({}|人民币)".format(riqi))
    a = soup.find_all('div', class_='table fr')
    find = a[:2]
    # print(find)
    mes1 = "北美周末票房榜\n"
    b=find[0]
    c=find[1]
    for data1 in b.find_all("ul", class_='list'):
        mes1 += "{}{}{}/{}\n".format(data1.find('li', class_='one topping').text,
                                     data1.find('a').text,
                                     data1.find('li', class_='six').text,
                                     data1.find('li', class_='seven').text,
                                     )
    print(mes1)
    mes2 = "内地一周票房榜\n"
    for data2 in c.find_all("ul", class_='list'):
        mes2 += "{}{}{}万/{}万\n".format(data2.find('li', class_='one topping').text,
                                       data2.find('a').text,
                                       data2.find('li', class_='six').text,
                                       data2.find('li', class_='seven').text,
                                       )
    print(mes2)


if __name__ == '__main__':
    html = gethtml()