如何解决如何使用相对URL的post方法将登录有效载荷发送到表单?
我正在尝试抓取需要登录的网站。问题在于登录表单的网址是这样的:
/customer/guest/index
问题是如何将登录信息发送到此post方法?
PS:我正在尝试使用this文章中提到的方法。
更新:这是我正在使用的代码
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]'
}
然后将其传递给发布方法
response = requests.post(
your_url,data=data
)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。