V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  Northxw  ›  全部回复第 14 页 / 共 14 页
回复总数  273
1 ... 5  6  7  8  9  10  11  12  13  14  
领导公司的职员反一波,成功坐上 BOSS 位置,去哪都是们开的。最多费点口舌。。。
2018-11-18 14:42:46 +08:00
回复了 Northxw 创建的主题 问与答 谈谈 pyspider 框架
@binux 我不知道是不是自己操作不当,给你看看程序。而且,我还需要老哥给我说说怎么配 json,我配了之后,运行程序就报错死循环。
from pyspider.libs.base_handler import *
from pymongo import MongoClient
import time


class Mongo(object):
def __init__(self):
# 初始化数据库
self.client = MongoClient()
self.db = self.client['lagou']
self.collection = self.db['python']

def insert(self, data):
# 将字典数据插入到数据库
if data:
self.collection.insert(data)

def __del__(self):
# 关闭数据库连接
self.client.close()

class Handler(BaseHandler):
crawl_config = {
'headers': {
'Host': 'www.lagou.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36'
},
'mongo': Mongo(),
}

@every(minutes=24 * 60)
def on_start(self):
self.crawl('https://www.lagou.com/zhaopin/Python/', callback=self.index_page, validate_cert=False,
params={'labelWords': 'label'})

# 设置任务有效期为两个小时(因为一般为 30 个页面左右)
@config(age=2 * 60 * 60)
def index_page(self, response):
for each in response.doc('.position_link').items():
self.crawl(each.attr.href, callback=self.detail_page, validate_cert=False)
time.sleep(1)
# 获取下一页链接
next = response.doc('.item_con_pager a:last-child').attr.href
self.crawl(next, callback=self.index_page, validate_cert=False)

@config(priority=2)
def detail_page(self, response):
return {
"company": response.doc('.job-name > .company').text(),
"job": response.doc('.job-name > .name').text(),
"salary": response.doc('.salary').text(),
"other": response.doc('.job_request span').text().split('/')[1:-1],
"labels": response.doc('.job_request li').text(),
"publish_time": "".join(response.doc('.publish_time').text().split()),
"job_advantage": response.doc('.job-advantage > p').text(),
"job_description": response.doc('.job_bt p').text(),
"work_address": response.doc('.work_addr').text().replace('查看地图', '')
}

def on_result(self, data):
self.crawl_config['mongo'].insert(data)
2018-11-18 09:50:09 +08:00
回复了 Northxw 创建的主题 问与答 谈谈 pyspider 框架
@binux 老哥 存储的时候 总是存那么几条数据。 可能是我的操作不当。。。
2018-11-17 23:01:05 +08:00
回复了 Northxw 创建的主题 问与答 谈谈 pyspider 框架
@snoopy1024 不清楚 看了下 Github 一年前就有人 issue 这问题了。。。
2018-11-17 22:38:53 +08:00
回复了 Northxw 创建的主题 问与答 谈谈 pyspider 框架
@laike9m 我是一个超级无敌很害羞的男生! emmm... 我都不信
2018-11-17 20:12:49 +08:00
回复了 Northxw 创建的主题 问与答 谈谈 pyspider 框架
明示吧 大哥 不要搞暗语了
2018-06-03 10:18:29 +08:00
回复了 wlchn 创建的主题 全球工单系统 UC 浏览器更新后无法使用“返回”了!
UC 浏览器已经抵挡不住 360,毒霸那一帮人了,猿弟,换 Google Chrome 吧,虽然比较吃 CPU,但是总比 FireFox 这个巨无霸要好很多勒
2018-06-02 16:29:47 +08:00
回复了 yangyaofei 创建的主题 全球工单系统 CSDN 博客网页 chrome 打开后 cpu 占用率 100%
emmm... Google Chrome 表示在 Windows 上面 cpu 也很高,但不至于你说的 100%,运存能占 300-500M,反正也是很高了。
2018-05-29 14:20:17 +08:00
回复了 Northxw 创建的主题 程序员 xshell5 输入中文怎么会变为问号,这个梗怎么破?
@owt5008137 十有九八我解码 /编码是正确的。
2018-05-16 23:37:21 +08:00
回复了 woshichuanqilz 创建的主题 Python Python for 赋值的问题请教一下?
才学疏浅,没看懂
1 ... 5  6  7  8  9  10  11  12  13  14  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2845 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 23ms · UTC 07:04 · PVG 15:04 · LAX 00:04 · JFK 03:04
Developed with CodeLauncher
♥ Do have faith in what you're doing.