用requests.post来爬取 www.lagou.com, 最经常看到的返回信息就是
‘status’: False, ‘msg’: ‘您操作太频繁,请稍后再访问’, ‘clientIp’: ‘117.136.41.xx’, ‘state’: 2402}
不是缺这个参数,就是缺那个,即便你添加Refere、User-Agent、Cookie,还有更难受的就是cookie信息经常会被识别为爬虫,就爬区不到,就得重新更换一个Cookie信息
用selenium+requests来用就简单多了。
import requests
from selenium import webdriver
from lxml import etree
import re
import time
class LagouSpider(object):
"""爬虫类"""
def __init__(self):
self.driver = webdriver.Chrome()
self.url = "https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&city=%e5%b9%bf%e5%b7%9e&suginput="
def run(self):
self.driver.get(self.url))
source = self.driver.page_source
if __name__ == "__main__":
LagouSpider().run()
就是这么简单,就可以爬取到页面的内容