簡體   English   中英

如何使用相對的 URL 將登錄有效負載發送到表單以進行 post 方法?

[英]How to send login payload to a form using relative URL for post method?

我正在嘗試抓取需要登錄的網站。 問題是登錄表單的 url 是這樣的:

/customer/guest/index

問題是我如何將登錄信息發送到這個 post 方法?

PS:我正在嘗試使用本文中提到的方法。

更新:這是我正在使用的代碼

from bs4 import BeautifulSoup
import requests
import csv


# Start the session
session = requests.Session()

# Create the payload
payload = {'CustomerLogin[email]':'<USERNAME>',
          'CustomerLogin[password]':'<PASSWORD>',
          'csrf_token': '<TOKEN>'
         }

# Post the payload to the site to log in
s = session.post(" https://avangemail.net/customer/guest/index", data=payload)
print('Logging in...')

# Navigate to the next page and scrape the data
s = session.get('https://avangemail.net/customer/lists/all-subscribers')

print('Getting information...')
print(s.text)
soup = BeautifulSoup(s.text, 'html.parser')
table = soup.find('table')
tbody = table.find('tbody')

headers = [td.text for td in thead.select("tr td td")]

filename = 'avang-export'
with open(r'.'+filename+'.csv', "w") as f:
    wr = csv.writer(f)
    wr.writerows([[td.text for td in row.find_all("td")] for row in tbody.select("tr")])
    data= {
              '_username':'[YOUR_USERNAME]', 
              '_password':'[YOUR_PASSWORD]'
          }

然后將其傳遞給 post 方法

response = requests.post(
    your_url,
    data=data
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM