新聞中心
1、requests模塊。直接攜帶cookies請(qǐng)求頁(yè)面。

創(chuàng)新互聯(lián)公司專(zhuān)注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)、華州網(wǎng)絡(luò)推廣、微信小程序、華州網(wǎng)絡(luò)營(yíng)銷(xiāo)、華州企業(yè)策劃、華州品牌公關(guān)、搜索引擎seo、人物專(zhuān)訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供華州建站搭建服務(wù),24小時(shí)服務(wù)熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
找到url,發(fā)送post請(qǐng)求存儲(chǔ)cookie。
2、selenium(瀏覽器自動(dòng)處理cookie)。
找到相應(yīng)的input標(biāo)簽,輸入文本,點(diǎn)擊登錄。
3、scrapy直接帶cookies。
找到url,發(fā)送post請(qǐng)求存儲(chǔ)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請(qǐng)求獲取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': '[email protected]',
'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): # 驗(yàn)證是否請(qǐng)求成功
print(re.findall('Learn Git and GitHub without any code!', response.body.decode()))以上就是python scrapy模擬登錄的方法,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
本文標(biāo)題:創(chuàng)新互聯(lián)Python教程:pythonscrapy模擬登錄的方法
當(dāng)前鏈接:http://m.fisionsoft.com.cn/article/dhipdhi.html


咨詢
建站咨詢
