0
点赞
收藏
分享

微信扫一扫

【定制开发】【M5】Python爬虫 - 获取【一品威客】最新发布需求,并实时通知用户

一天清晨 2022-02-03 阅读 106

背景

有个朋友计划拓展业务渠道,准备在众包平台上接单,他的主营产品是微信小程序,因此他想第一时间收到客户发出的需求信息,然后第一时间联系客户,这样成交率才能够得到保障,否则单早都被其他同行接完了,他的黄花菜也就都凉了。

开发环境


  • 开发语言 Python ,开发架构Scrapy,非 Python 莫属,数据采集的神器!
  • 开发工具 PyCharm;

功能设计


  • 实时通知:采用发邮件方式通知,将邮箱绑定到微信,实现实时通知的效果。
  • 过滤模块:根据标题和内容双重过滤关键词,不符合要求的订单丢弃,符合要求的订单实时通知。
  • 配置模块:采用json文件配置。

关键代码

  • 采集模块
# -*- coding: utf-8 -*-
import time

import scrapy
from scrapy import Selector
from .. import common


class YpwktaskSpider(scrapy.Spider):
name = 'ypwktask'
allowed_domains = ['ypwk.com']
start_urls = ['https://www.epwk.com/task/develop/']

def parse(self, response):
# pass
# price = response.xpath('//h3[@class="a2"]/b/text()').getall()
# name= response.xpath('//h3[@class="a2"]//@indus_pname').getall()
# desc = response.xpath('//h3[@class="a2"]//@desc').getall()
# url = response.xpath('//h3[@class="a2"]//@url').getall()
nodes = response.xpath('//h3[@class="a2"]').getall()
for node in nodes:
# print(node)
price = Selector(text=node).xpath('//b/text()').get().replace(u'\xa0', u' ')
name = Selector(text=node).xpath('//@indus_pname').get().replace(u'\xa0', u' ')
desc = Selector(text=node).xpath('//@desc').get().replace(u'\xa0', u' ')
url = Selector(text=node).xpath('//@url').get()
urgent = Selector(text=node).xpath('//span//@title ').get()
if urgent is None:
urgent = ''
id = Selector(text=node).xpath('//@id ').get()

print(name, price, desc, url, urgent, id)
sended_id = common.read_taskid()
if int(id) > sended_id:
subject = "YPWK " + id + " " + name
# content = price + "\n" + desc + "\n" + url + "\n" + urgent + "\n"
content = "%s <p> %s <p> < a href=%s>%s</ a> <p> %s" % (price, desc, url, url, urgent)
if common.send_mail(subject, content):
common.write_taskid(id=int(id))
print("mail: send task <%s> sucess " % id)
else:
print("mail: send task <%s> fail " % id)
else:
print("mail: task is already sended <%s>" % id)
time.sleep(3)
  • 通知模块
def send_mail(subject, content):
sender = u'xxxxx@qq.com' # 发送人邮箱
passwd = u'xxxxxx' # 发送人邮箱授权码
receivers = u'xxxxx@qq.com' # 收件人邮箱

# subject = u'一品威客 开发任务 ' #主题
# content = u'这是我使用python smtplib模块和email模块自动发送的邮件' #正文
try:
# msg = MIMEText(content, 'plain', 'utf-8')
msg = MIMEText(content, 'html', 'utf-8')
msg['Subject'] = subject
msg['From'] = sender
msg['TO'] = receivers

s = smtplib.SMTP_SSL('smtp.qq.com', 465)
s.set_debuglevel(1)
s.login(sender, passwd)
s.sendmail(sender, receivers, msg.as_string())
return True
except Exception as e:
print(e)
return False

总结

程序上线后稳定运行,实现了预期的效果,接单率效果杠杠的!

附:Scrapy 结构图

【定制开发】【M5】Python爬虫 - 获取【一品威客】最新发布需求,并实时通知用户_python

-------------------------------------------------------------------------------------------------------------------

本次分享结束,欢迎讨论!



举报

相关推荐

0 条评论