import requests
from bs4 import BeautifulSoup url = 'https://github.com/login'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
'Referer': 'https://github.com/',
'Upgrade-Insecure-Requests': '1', # 此处的1 必须是字符串,不是数字
'Host': 'github.com',
'Connection': 'keep-alive',
'Accept-Language': 'zh-CN,zh;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'}
res1 = requests.get(url, headers=headers)
# 检验
print(res1.status_code)
print(res1.reason)
# 通过解析页面来获取动态token
soup = BeautifulSoup(res1.text, 'lxml')
tag_input = soup.find(name='input', attrs={'name': 'authenticity_token'})
authenticity_token = tag_input.get('value')
data = {'commit': 'Sign+in',
'utf8': '✓',
'authenticity_token': authenticity_token,
'login': '295345t54341@qq.com',
'password': '234523456345'} cookies = res1.cookies.get_dict()
# 这里的url是https://github.com/session,不是https://github.com/login
res2 = requests.post(url='https://github.com/session', headers=headers, cookies=cookies, data=data)
print(authenticity_token)
print(res2.status_code)
print(res2.reason)
cookies.update(res2.cookies.get_dict())
res3 = requests.get(url='https://github.com/settings/repositories',
cookies=cookies,
headers=headers
) print(res3.url)
print(res3.status_code)
print(res3.reason) soup3 = BeautifulSoup(res3.text, 'lxml')
project = soup3.find(name='div', attrs={'class': 'listgroup'})
print(project)
project_list = project.find_all(name='a', attrs={'class': 'mr-1'})
for i in project_list:
project_name = i.text
project_ = i.get('href')
project_href = 'https://github.com/' + project_.split('/', maxsplit=1)[1]
print('项目名称:%s , 项目连接:%s' % (project_name, project_href), '\n') # 爬取github注意事项,1.以后携带的cookie使用的是登录后的cookie
# 2.需要在登录页面找到token,该token是动态的需要使用bs4,或者正则表达式来获取动态值

爬取github项目。的更多相关文章

  1. python爬取github数据

    爬虫流程 在上周写完用scrapy爬去知乎用户信息的爬虫之后,github上star个数一下就在公司小组内部排的上名次了,我还信誓旦旦的跟上级吹牛皮说如果再写一个,都不好意思和你再提star了,怕你们 ...

  2. 模拟登陆并爬取Github

    因为崔前辈给出的代码运行有误,略作修改和简化了. 书上例题,不做介绍. import requests from lxml import etree class Login(object): def ...

  3. 爬取github上流行的python项目

    # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import requests from pyquery import PyQ ...

  4. window 下拉取github项目失败 (Permission denied (publickey))

    原因是github 帐号ssh 失效或者没有配置 1.找到gitcmd 并进入 2.在gitcmd 下切换到 安装git路劲\Git\usr\bin 3.提示在C:\Users\Administrat ...

  5. scrapy项目4:爬取当当网中机器学习的数据及价格(CrawlSpider类)

    scrapy项目3中已经对网页规律作出解析,这里用crawlspider类对其内容进行爬取: 项目结构与项目3中相同如下图,唯一不同的为book.py文件 crawlspider类的爬虫文件book的 ...

  6. scrapy爬取校花网男神图片保存到本地

    爬虫四部曲,本人按自己的步骤来写,可能有很多漏洞,望各位大神指点指点 1.创建项目 scrapy startproject xiaohuawang scrapy.cfg: 项目的配置文件xiaohua ...

  7. 开源项目-网上公开http代理爬取、简单分类

    爬取网上公开免费代理(http/socks),解析入库,可满足需要切换IP的场景(爬虫.投票等)需求. 项目地址: https://github.com/Jwnie/proxyservice 1.采用 ...

  8. Python爬虫与一汽项目【一】爬取中海油,邮政,国家电网问题总结

    项目介绍 中国海洋石油是爬取的第一个企业,之后依次爬取了,国家电网,中国邮政,这三家公司的源码并没有多大难度, 采购信息地址: 国家电网电子商务平台 http://ecp.sgcc.com.cn/pr ...

  9. Python爬虫开源项目代码,爬取微信、淘宝、豆瓣、知乎、新浪微博、QQ、去哪网等 代码整理

    作者:SFLYQ 今天为大家整理了32个Python爬虫项目.整理的原因是,爬虫入门简单快速,也非常适合新入门的小伙伴培养信心.所有链接指向GitHub,祝大家玩的愉快 1.WechatSogou [ ...

随机推荐

  1. 工控随笔_20_西门子_WinCC的VBS脚本_09_常量和流程控制_02

    vbs不但提供了分支结构,还提供了丰富的循环形式.一共有3种循环: 1.for循环 2.do...loop循环 3.while循环 各种循环有各自的特点,在使用的时候可以进行转换. 前面已经描述过Fo ...

  2. note 11 字典

    字典 Dictionary +什么是字典? +一系列的"键-值(key-value)"对 +通过"键"查找对应的"值" +类似纸质字典,通过 ...

  3. 8、Zookeeper分布式锁

    基础知识:http://www.cnblogs.com/LiZhiW/p/4931577.html 1 可重入读写锁示例代码如下(lock.acquire加几个,就必须使用几个lock.release ...

  4. C#调用VisionPro工程文件

    添加一个按钮与控件,双击按钮,在程序中写下一下代码, CogJobManager mymanger = (CogJobManager)CogSerializer.LoadObjectFromFile( ...

  5. Kafka connect in practice(3): distributed mode mysql binlog ->kafka->hive

    In the previous post Kafka connect in practice(1): standalone, I have introduced about the basics of ...

  6. vue-cli 发布部署IIS

    有些时候我们的服务器不用的是node,也许是IIS,这样就需要把工程构建出来,与IIS集成. 构建的命令如下 cnpm run build 将其中的dist文件夹拷贝出来,放到IIS的发布目录,在浏览 ...

  7. Mac端解决(含修改8.0.13版的密码):Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

    1. 安装mysql但是从来没启动过,今天一启动就报错: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2 ...

  8. 通过ldap验证svn服务

    1.简单介绍: 这里需要介绍一点的就是svn服务器的验证是需要通过SASL机制的,那么SASL全称为(Simple Authentication and security Layer),是一种用来扩充 ...

  9. 小程序2-基本架构讲解(一)JSON配置与详解

    项目里边生成了不同类型的文件: .json 后缀的 JSON 配置文件 .wxml 后缀的 WXML 模板文件 .wxss 后缀的 WXSS 样式文件 .js 后缀的 JS 脚本逻辑文件 JSON 配 ...

  10. Linux 添加新分区和 移动 /home到新挂载分区

    https://blog.csdn.net/lyd135364/article/details/78623119 https://www.cnblogs.com/saszhuqing/p/871664 ...