GITHUB上传流程如下
1.进入Github首页,点击New repository新建一个项目
2.填写相应信息后点击create即可
Repository name: 仓库名称
Description(可选): 仓库描述介绍
Public, Private : 仓库权限(公开共享,私有或指定合作者)
Initialize this repository with a README: 添加一个README.md
gitignore: 不需要进行版本管理的仓库类型,对应生成文件.gitignore
license: 证书类型,对应生成文件LICENSE
3.点击Clone or dowload会出现一个地址,copy这个地址备用。
4.接下来就到本地操作了,首先右键你的项目,如果你之前安装git成功的话,右键会出现两个新选项,分别为Git Gui Here,Git Bash Here,这里我们选择Git Bash Here,进入如下界面,Test_Bluetooth即为我的项目名。
5.接下来输入如下代码(关键步骤),把github上面的仓库克隆到本地
6.这个步骤以后你的本地项目文件夹下面就会多出个文件夹,该文件夹名即为你github上面的项目名,如图我多出了个Test文件夹,我们把本地项目文件夹下的所有文件(除了新多出的那个文件夹不用),其余都复制到那个新多出的文件夹下.
7.把文件全部放入这个文件夹,然后cd <文件名>
接下来依次输入以下代码即可完成其他剩余操作:
git add .
git commit -m “提交信息”
git push -u origin master (输入你的账号)
最后我的代码地址:https://github.com/a371057600/python-paChong-
把
pipline.py中的数据库改成你的数据库哦,详情操作,请自己去百度找SCRAPY的数据库连接教程,非常简单
import pymysql
class JianshuSpiderPipeline(object):
def __init__(self):
dbparams = {
'host': '127.0.0.1',
'port': 3306,
'user': 'root',
'password': '7923161',
'database': 'jianshu',
'charset': 'utf8',
}#这里记得改成你自己的数据库,不然你爬起来会不停地出错哦.
self.conn = pymysql.connect(**dbparams)
self.cursor = self.conn.cursor()
self._sql = None
def process_item(self, item, spider):
self.cursor.execute(self.sql, (item['title'],item['content'],item['author'],item['avatar'],item['pub_time'],item['origin_url'],item['article_id']))
self.conn.commit()
return item
@property
def sql(self):
if not self._sql:
self._sql = """
insert into article(id,title,content,author,avatar,pub_time,origin_url,article_id) values(null,%s,%s,%s,%s,%s,%s,%s)
"""
return self._sql
return self._sql