分布式爬虫的搭建

scrapy-redis使用

技术栈:
python
scrapy
scrapy-redis
redis
mysql
windows
ubuntu

mysql:
1. 创建一个数据库tencent
2. 创建一个表tencent_table
create table tencent_table(
name varchar(100),
addr varchar(50),
time varchar(20),
type varchar(30),
responsibility varchar(1000),
requirement varchar(1000),
);
在ubuntu配置mysql的远程连接
同时配置redis的远程连接

招聘网站的抓取:
https://careers.tencent.com/search.html

1.页面分析
使用浏览器的开发者工具分析页面
查看网络–响应、预览
动态页面
2. check ajax异步请求
动态地址:
2.1 一级页面数据https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1622297360154&countryId=&cityId=&bgIds=&productId=&categoryId=&parentCategoryId=&attrId=&keyword=php&pageIndex=1&pageSize=10&language=zh-cn&area=cn
可以从json数据中,解析出详情页的PostId。
2.2 二级页面数据
https://careers.tencent.com/tencentcareer/api/post/ByPostId?timestamp=1622303291537&postId=1398635661610721280&language=zh-cn

  1. 创建scrapy项目
    在 items.py 定义抓取的字段
    name/addr/time/type/responsibility/requirement
  2. 编写爬虫文件,如下:
import scrapy
import time
import json
from ..items import TencentItem

class TencentSpider(scrapy.Spider):
    name = 'tencent'
    allowed_domains = ['careers.tencent.com']
    #用户输入,如:python /java
    input_key = input("输入岗位的开发语言类型, 如python:").strip()
    #获取时间戳
    ts = int(time.time()*1000)
    first_url = "https://careers.tencent.com/tencentcareer/api/post/Query?timestamp={}&countryId=&cityId=&bgIds=&productId=&categoryId=&parentCategoryId=&attrId=&keyword={}&pageIndex=1&pageSize=10&language=zh-cn&area=cn"
    start_urls = [first_url.format(ts,input_key)]

    def parse
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

laufing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值