繁体   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