您好,登錄后才能下訂單哦!
今天小編給大家分享一下python scrapy.Request發(fā)送請(qǐng)求的方式是什么的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識(shí),所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
說明
1、使用scrapy.Request()指定method,body參數(shù)發(fā)送post請(qǐng)求。
2、使用scrapy.FormRequest()發(fā)送post請(qǐng)求,也可以發(fā)送表格和ajax請(qǐng)求。
實(shí)例
import scrapy class Git2Spider(scrapy.Spider): name = 'git2' allowed_domains = ['github.com'] start_urls = ['http://github.com/login'] def parse(self, response): username = 'GitLqr' password = 'balabala' # 從登錄頁面響應(yīng)中解析出post數(shù)據(jù) token = response.xpath('//input[@name="authenticity_token"]/@value').extract_first() post_data = { 'commit': 'Sign in', 'authenticity_token': token, 'login': username, 'password': password, 'webauthn-support': 'supported', } print(post_data) # 針對(duì)登錄url發(fā)送post請(qǐng)求 yield scrapy.FormRequest( url='https://github.com/session', callback=self.after_login, formdata=post_data ) def after_login(self, response): yield scrapy.Request('https://github.com/GitLqr', callback=self.check_login) def check_login(self, response): print(response.xpath('/html/head/title/text()').extract_first())
以上就是“python scrapy.Request發(fā)送請(qǐng)求的方式是什么”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會(huì)為大家更新不同的知識(shí),如果還想學(xué)習(xí)更多的知識(shí),請(qǐng)關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。