import requests
import time
from random import randint
from bs4 import BeautifulSoup as bs
def req_info(i):
    url = 'https://smtebooks.us/getfile/{}'.format(i)
    headers = {
        'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'
    }

    res = requests.get(url,headers=headers,allow_redirects=False)
    try:
        res.headers['Location']
    except KeyError:
        pass
    else:
        return 'no content'
    res_decode = res.content.decode('utf-8')
    soup = bs(res_decode,'lxml')
    url = 'no'
    title = 'no'
    dl_url = 'no'
    for _ in soup.find_all('div',class_='priging_thumb'):
        url = 'https://smtebooks.us'+_.a.get('href')
        title = _.a.get('title')
    for _ in soup.find_all('a',class_='Download btn btn-block btn-lg btn-success'):
        dl_url = _.get('href')
    print(i,url,title,dl_url)
    with open('smtebooks.csv','a',encoding='utf-8') as f:
        #f.write('{},{},{},{}\n'.format(i,title,url,dl_url))
        #考虑到title有特殊字符
        f.write('{},"{}",{},{}\n'.format(i,title,url,dl_url))
    return url,title,dl_url
for i in range(20,13517):#13516
    print(i)
    req_info(i)
    k = randint(2,10)
    print('sleep',k,'s')
    time.sleep(k)
9
9 https://smtebooks.us/book/9/beginning-f-40-2nd-edition-pdf Beginning F# 4.0 2nd Edition https://drive.google.com/uc?export=download&id=0B4hhbFaItiPxUGRKVnQtWDhBMWM
sleep 3 s
10
10 https://smtebooks.us/book/10/head-first-ajax-pdf Head First Ajax 1st Edition https://drive.google.com/uc?export=download&id=0B4hhbFaItiPxbUlPdnlYckJ6MG8
sleep 3 s
11
11 https://smtebooks.us/book/11/c-24-hour-trainer-2nd-edition-pdf C# 24-Hour Trainer 2nd Edition https://drive.google.com/uc?export=download&id=0B4hhbFaItiPxcnRkMkNLSE44TFU
sleep 2 s
12
sleep 2 s
13
sleep 1 s
14
sleep 2 s
15
sleep 2 s
16
sleep 2 s
17
sleep 3 s
18
sleep 1 s
19
19 https://smtebooks.us/book/19/professional-aspnet-4-c-vb-pdf Professional ASP.NET 4 in C# and VB 1st Edition /Book/DownloadFile/19/professional-aspnet-4-c-vb-pdf
sleep 2 s

标签: smtebooks

添加新评论