import requests
from lxml import etree
import pymongoclass article(object):def __init__(self):# 创建连接,ip地址和端口号self.client = pymongo.MongoClient("iP地址", 端口号)# 连接的数据库db = self.client.数据库的名字# 账号密码的认证db.authenticate("账号", "密码")# 连接的表_table = db.表名def write_to_mongodb(self):url = '.html'response = (url)content = t.decode('gb2312')tree = etree.HTML(content)# 转为字符串p_list = tree.xpath('//div[@class="help_t_int"]/p')text = ''for num in range(len(p_list)):conten = string(p_list[num], encoding="utf-8",pretty_print=True,method="xml").decode('utf-8')text += contendata = {'article_name': '易乐11选5奖项规则','article_sub_name': '','lottery_name': '易乐11选5','article_tag': '','article_class_name': '奖项规则','article_recommend': '','article_from': '','article_from_url': url,'article_author': '','article_content': text,'article_abstract': '','article_img': '','is_delete': _table.insert(data)article().write_to_mongodb()
本文发布于:2024-01-29 18:55:49,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170652575317558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |