环境: windows+python3.6+pycharm(非必须)
引用的python库/模块:requests, bs4, os, random,you-get
准备知识:requests的应用,BeautifulSoup的find_all(),os.system(“cmd命令”),you-get
爬取步骤:
1.对于爬虫,我习惯都用上ip代理池,虽然有的网站没有反爬虫策略,但是用上也无大碍。将ip代理池封装为一个模块可以随时调用
直接贴代码:get_ip.py
import requests from bs4 import BeautifulSoup import random head = { 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.0 x64; en-US; rv:1.9pre) Gecko/2008072421 Minefield/3.0.2pre', 'ue': 'utf-8', } def get_ip_list(): # 从IP代理网站1直接爬取大量的ip url = 'http://www.xicidaili.com/nn/' &nb