拉勾网,即便我requests不你的心,我也要selenium到你的人

本文介绍使用selenium和requests库解决爬取拉勾网职位信息时遇到的反爬虫问题,通过模拟真实浏览器行为,成功获取页面源代码。

用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()

就是这么简单,就可以爬取到页面的内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值