... 등 페이지를 검색 할 수 session.get(someurl, ...)
를 사용합니다. 이와 같이 :
response = requests.get(url, auth = ('username', 'password'))
자세한 내용은 Authentication Documentation 요청을 참조하십시오.
크롬의 개발자 도구를 사용하면 작성하고 제출할 양식이 포함 된 HTML 페이지의 요소를 검사 할 수 있습니다. 이것이 어떻게 수행되는지에 대한 설명은 here으로 가십시오. 게시 요청의 데이터 인수를 채우기 위해 필요한 데이터를 찾을 수 있습니다. 액세스하고있는 사이트의 보안 인증서를 확인하는 것에 대해 걱정하지 않으려는 경우 get 인수 목록에 지정할 수도 있습니다. 다음과 같이
<textarea id="text" class="wikitext" name="text" cols="80" rows="20">
This is where your edited text will go
</textarea>
<input type="submit" id="save" name="save" value="Submit changes">
그런 다음 파이썬 코드가이 양식에 게시하는 것입니다 :
import requests
from bs4 import BeautifulSoup
url = "http://www.someurl.com"
username = "your_username"
password = "your_password"
response = requests.get(url, auth=(username, password), verify=False)
# Getting the text of the page from the response data
page = BeautifulSoup(response.text)
# Finding the text contained in a specific element, for instance, the
# textarea element that contains the area where you would write a forum post
txt = page.find('textarea', id="text").string
# Finding the value of a specific attribute with name = "version" and
# extracting the contents of the value attribute
tag = page.find('input', attrs = {'name':'version'})
ver = tag['value']
# Changing the text to whatever you want
txt = "Your text here, this will be what is written to the textarea for the post"
# construct the POST request
form_data = {
'save' : 'Submit changes'
'text' : txt
}
post = requests.post(url,auth=(username, password),data=form_data,verify=False)
당신은 크롬을 사용할 수 있습니다 HTML 페이지는 이러한 요소가
경우 웹 양식 게시에 사용하는 관리자가 어떤 값이 브라우저에서 생성 된 게시물 요청에 전달되었는지 확인한 다음 거기에서부터 이동합니다. – bossylobster