新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
創(chuàng)新互聯(lián)Python教程:pythonscrapy模擬登錄的方法
1、requests模塊。直接攜帶cookies請求頁面。

創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網綜合服務,包含不限于網站設計、成都網站設計、華州網絡推廣、微信小程序、華州網絡營銷、華州企業(yè)策劃、華州品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)公司為所有大學生創(chuàng)業(yè)者提供華州建站搭建服務,24小時服務熱線:13518219792,官方網址:www.cdcxhl.com
找到url,發(fā)送post請求存儲cookie。
2、selenium(瀏覽器自動處理cookie)。
找到相應的input標簽,輸入文本,點擊登錄。
3、scrapy直接帶cookies。
找到url,發(fā)送post請求存儲cookie。
# -*- coding: utf-8 -*-
import scrapy
import re
class GithubLoginSpider(scrapy.Spider):
name = 'github_login'
allowed_domains = ['github.com']
start_urls = ['https://github.com/login']
def parse(self, response): # 發(fā)送Post請求獲取Cookies
authenticity_token = response.xpath('//input[@name="authenticity_token"]/@value').extract_first()
utf8 = response.xpath('//input[@name="utf8"]/@value').extract_first()
commit = response.xpath('//input[@name="commit"]/@value').extract_first()
form_data = {
'login': 'pengjunlee@163.com',
'password': '123456',
'webauthn-support': 'supported',
'authenticity_token': authenticity_token,
'utf8': utf8,
'commit': commit}
yield scrapy.FormRequest("https://github.com/session", formdata=form_data, callback=self.after_login)
def after_login(self, response): # 驗證是否請求成功
print(re.findall('Learn Git and GitHub without any code!', response.body.decode()))以上就是python scrapy模擬登錄的方法,希望對大家有所幫助。更多Python學習指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
網頁標題:創(chuàng)新互聯(lián)Python教程:pythonscrapy模擬登錄的方法
轉載來于:http://www.dlmjj.cn/article/dhipdhi.html


咨詢
建站咨詢
