I want to extract question and answer from PayPal stackoverflow. So for that I was thinking to use a API and extract the data. But here I am not sure how to login when using the GET request. I am using the below code and when passing the cooking value from the session I am not able to login.
import requests
from bs4 import BeautifulSoup
def extract_stackoverflow_data(url, headers=None):
response = requests.get(url, headers=headers)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
print(soup)
# Extract question title
question_title = soup.find('a', class_='question-hyperlink').get_text().strip()
# Extract question body
question_body = soup.find('div', class_='postcell').find('div', class_='s-prose js-post-body').get_text().strip()
# Extract answers
answers = []
for answer in soup.find_all('div', class_='answer'):
answer_body = answer.find('div', class_='s-prose js-post-body').get_text().strip()
answers.append(answer_body)
return {
'title': question_title,
'question': question_body,
'answers': answers
}
else:
print(f"Error fetching Stack Overflow page: {response.status_code}")
return None
# Example Stack Overflow Enterprise question URL
stackoverflow_enterprise_url = 'https://your-company.stackenterprise.co/questions/1234/how-to-extract-data'
# Headers with access token
headers = {
'Authorization': f'Bearer {access_token}' # Replace with your actual access token
#OR
'X-API-key': "key value'
'Cookie': 'session=your-session-cookie-value'
}
data = extract_stackoverflow_data(stackoverflow_enterprise_url, headers)
if data:
print(f"Title: {data['title']}")
print(f"Question: {data['question']}")
for i, answer in enumerate(data['answers']):
print(f"Answer {i + 1}: {answer}")
##OUTPUT
Welcome to Stack Overflow Enterprise </p>
</div>
<div class="wmx3 mx-auto p24 bg-white bar-lg bs-xl" id="formContainer">
<a class="d-block s-btn s-btn__filled" href="/users/samlstart?returnurl=https%3a%2f%2fyour-company.stackenterprise.co%2fquestions%2f10831">Log in</a>
So how can I login into my enterprise stackoverflow 1st? I have tried using cookie and API key.