Exemple #1
0
 def insert_new_comment(x, comment_type, comment,create_time):
     statement = 'INSERT INTO jd_comment (comment_type,comment,create_time) ' \
                 'VALUES (\'%s\',\'%s\')' \
                 % (comment_type, comment,create_time)
     log.debug(statement)
     cur_item.execute(statement)
     db_item.commit()
Exemple #2
0
def save_comment():
    comments = driver.find_elements_by_class_name("comment-con")
    for comment in comments:
        commentContent = comment.text
        log.debug(commentContent)
        create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        Sql.insert_new_comment(comment_type, commentContent,create_time)
Exemple #3
0
def handle_client(request):
    """handle wechat event and client message"""

    wechat = Wechat()
    args = request.args
    # check request signature
    if not wechat.check_signature(args.get('signature'), args.get('timestamp'), args.get('nonce')):
        return ''
    try:
        wechat.parse_data(request.data)
    except ParseError:
        log.error('Parse post data error, data: %s'%str(request.data))
        return ''

    log.debug('Request: %s'%str(request.data))

    message = wechat.get_message()
    response = ''
    # normal message
    if isinstance(message, TextMessage):
        response = wechat.response_text(content=turing_robot(message.content, message.source))
    elif isinstance(message, VoiceMessage):
        response = wechat.response_text(content=u'语音信息')
    elif isinstance(message, ImageMessage):
        response = wechat.response_text(content=u'图片信息')
    elif isinstance(message, VideoMessage):
        response = wechat.response_text(content=u'视频信息')
    elif isinstance(message, ShortVideoMessage):
        response = wechat.response_text(content=u'小视频信息')
    elif isinstance(message, LinkMessage):
        response = wechat.response_text(content=u'链接信息')
    elif isinstance(message, LocationMessage):
        response = wechat.response_text(content=u'地理位置信息')
    # event message
    elif isinstance(message, EventMessage):  # 事件信息
        if message.type == 'subscribe':  # 关注事件(包括普通关注事件和扫描二维码造成的关注事件)
            if message.key and message.ticket:  # 如果 key 和 ticket 均不为空,则是扫描二维码造成的关注事件
                response = wechat.response_text(content=u'用户尚未关注时的二维码扫描关注事件')
            else:
                response = wechat.response_text(content=u'普通关注事件')
        elif message.type == 'unsubscribe':
            response = wechat.response_text(content=u'取消关注事件')
        elif message.type == 'scan':
            response = wechat.response_text(content=u'用户已关注时的二维码扫描事件')
        elif message.type == 'location':
            response = wechat.response_text(content=u'上报地理位置事件')
        elif message.type == 'click':
            response = wechat.response_text(content=u'自定义菜单点击事件')
        elif message.type == 'view':
            response = wechat.response_text(content=u'自定义菜单跳转链接事件')
        elif message.type == 'templatesendjobfinish':
            response = wechat.response_text(content=u'模板消息事件')

    if isinstance(response, unicode):
        response = response.encode('utf-8')

    log.debug('Response: %s'%response)

    return make_response(response)
Exemple #4
0
 def delete_all_comment(cls):
     statement = 'truncate table jd_comment'
     log.debug(statement)
     cur_item.execute(statement)
Exemple #5
0
 def delete_comment(cls, comment_id):
     statement = 'DELETE FROM jd_comment WHERE id=\'%s\'' % comment_id
     log.debug(statement)
     cur_item.execute(statement)
Exemple #6
0
# 爬取京东商品评论并存储到数据库
# shatong
# 2020-01-10
import time
from mysql.sql import Sql
from selenium import webdriver
import configparser
from log.logger import log

# 从配置文件中读取相关参数
conf = configparser.ConfigParser()
conf.read('config/conf.ini', encoding='utf-8')
HostUrl = conf.get('conf', 'host')
comment_type = conf.get('conf', 'comment_type')
print(HostUrl)
log.debug("------已取得url,准备爬取评论------")
driver = webdriver.Chrome()
driver.maximize_window()


# 打开京东详情页
def py_jd_product_detail():
    try:

        driver.get(HostUrl)
        time.sleep(10)
        gun()
        closeAD()
    except Exception as e:
        log.error("-------详情页面打开失败,准备重试------")
        driver.close()