新聞中心
這里有您想知道的互聯網營銷解決方案
創(chuàng)新互聯Python教程:python scrapy.Request發(fā)送請求的方式
說明

10年積累的成都網站設計、成都做網站、外貿網站建設經驗,可以快速應對客戶對網站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網絡服務。我雖然不認識你,你也不認識我。但先網站策劃后付款的網站建設流程,更有青浦免費網站建設讓你可以放心的選擇與我們合作。
1、使用scrapy.Request()指定method,body參數發(fā)送post請求。
2、使用scrapy.FormRequest()發(fā)送post請求,也可以發(fā)送表格和ajax請求。
實例
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'
# 從登錄頁面響應中解析出post數據
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)
# 針對登錄url發(fā)送post請求
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ā)送請求的方式,希望對大家有所幫助。更多Python學習指路:創(chuàng)新互聯python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
分享題目:創(chuàng)新互聯Python教程:python scrapy.Request發(fā)送請求的方式
文章鏈接:http://m.5511xx.com/article/ccopsed.html


咨詢
建站咨詢
