I am trying to get the questions and answers from StackApi to train a deep learning model. I have the problem that I don't understand how to use the custom filters so that I only get the body of the question.
This is my code:
from stackapi import StackAPI
import torch
import torch.nn as nn
SITE = StackAPI('stackoverflow')
SITE.max_pages=1
SITE.page_size=1
data = SITE.fetch('questions', tagged='python',filter = '!*SU8CGYZitCB.D*(BDVIficKj7nFMLLDij64nVID)N9aK3GmR9kT4IzT*5iO_1y3iZ)6W.G*', sort = 'votes')
for quest in data['items']:
question = quest['title']
print(question)
question_id = quest['question_id']
print (question_id)
dataAnswer = SITE.fetch('questions/{ids}/answers', ids=[question_id], filter='withbody')
print(dataAnswer)
My results for dataAnswer:
{'backoff': 0, 'has_more': True, 'page': 1, 'quota_max': 300, 'quota_remaining': 300, 'total': 0, 'items': [{'owner': {'reputation': 404, 'user_id': 11182732, 'user_type': 'registered', 'profile_image': 'https://lh6.googleusercontent.com/-F2a9OP4yGHc/AAAAAAAAAAI/AAAAAAAADVo/Mn4oVgim-m8/photo.jpg?sz=128', 'display_name': 'Aditya patil', 'link': 'https://stackoverflow.com/users/11182732/aditya-patil'}, 'is_accepted': False, 'score': 8, 'last_activity_date': 1609856797, 'last_edit_date': 1609856797, 'creation_date': 1587307868, 'answer_id': 61306333, 'question_id': 231767, 'content_license': 'CC BY-SA 4.0', 'body': '<p><strong>The yield keyword is going to
replace return in a function definition to create a generator.</strong></p>
<pre><code>def create_generator():
for i in range(100):
yield i
myGenerator = create_generator()
print(myGenerator)
# <generator object create_generator at 0x102dd2480>
for i in myGenerator:
print(i) # prints 0-99
</code></pre>
<p>When the returned generator is first used—not in the assignment but the for loop—the function definition will execute until it reaches the yield statement. There, it will pause (see why it’s called yield) until used again. Then, it will pick up where it left off. Upon the final iteration of the generator, any code after the yield command will execute.</p>
<pre><code>def create_generator():
print("Beginning of generator")
for i in range(4):
yield i
print("After yield")
print("Before assignment")
myGenerator = create_generator()
print("After assignment")
for i in myGenerator :
print(i) # prints 0-3
"""
Before assignment
After assignment
Beginning of generator
0
1
2
After yield
</code></pre>
<p>The <strong>yield</strong> keyword modifies a function’s behavior to produce a generator that’s paused at each yield command during iteration. The function isn’t executed except upon iteration,
which leads to improved resource management, and subsequently, a better overall performance. Use generators (and yielded functions) for creating large data sets meant for single-use iteration.</p>
'}]}
Now I want to get just the body of the result. Can I replace the withbody
filter with a custom one and if so which one?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…