电影天堂数据爬取、保存

import requests,re
from pymysql_conn import Mysql_connect
url = 'http://www.ygdy8.net/html/gndy/dyzz/list_23_{}.html'

s = requests.session()
s.keep_alive = False

mysql_object = Mysql_connect()
sql = 'insert into data_ygdy (title,magnet,torrent) value({},{},{})'

for i in range(1,3):
    url_t = url.format(i)

    response = requests.get(url_t)
    response.encoding = 'gb2312'
    # print(response.text)
    html_str = response.text
    a_list = re.findall(',html_str)
    # print(a_list)
    # a_list = a_list[1:]
    for a in a_list:
        a_url = 'http://www.ygdy8.net' + a
        res = requests.get(a_url)
        res.encoding = 'gb2312'
        html = res.text
        # print(html)
        mv_title = re.search('

(.*),html).group(1) # print(mv_title) mv_magnet = re.search('/>,html).group(1) mv_torrent = re.search('ddf">ft',html).group(1) # print(mv_title,mv_magnet,mv_torrent) mysql_object.execute_sql(sql.format(repr(mv_title), repr(mv_magnet), repr(mv_torrent)))

你可能感兴趣的:(电影天堂数据爬取、保存)