Python-爬虫小计

python学习网 2019-01-19 10:43:02
 1 # -*-coding:utf8-*-
 2 import requests
 3 from bs4 import BeautifulSoup
 4 import time
 5 import os
 6 import urllib
 7 import re
 8 import json
 9 
10 
11 requests.packages.urllib3.disable_warnings()
12 
13 proxies = {"http": "http:.............................",
14            "https": "https:............................."}
15 headers = {
16     'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'
17 }
18 
19 def get_bs(url):
20     res = requests.get(url, proxies=proxies, headers=headers, verify=False)
21     bs = BeautifulSoup(res.content, 'lxml')
22     return bs
23 
24 def get_first_url():
25     first_url_list = []
26     page = 213
27     for i in range(page):
28         root_url =  "https://www.model61.com/mold.php?page={}".format(str(i+1))
29         bs = get_bs(root_url)
30         for i in  bs.select("dt a"):
31             src = i.get('href')
32             if "php" in src:
33                 first_url = "https://www.model61.com/{}".format(src)
34                 first_url_list.append(first_url)
35     return first_url_list
36 
37 
38 
39 if __name__ == '__main__':
40     get_first_url()

 

阅读(2638) 评论(0)