1

どうすればそれを削除できますか? 私は非常に多くのことを試しましたが、このエラーを自分で打ち負かすことに疲れ果てています。私はこれを見て、それを乗り越えようとして最後の 3 時間を費やし、このコードに降伏しました。助けてください。

最初の "for" ステートメントは、news.google.com から記事のタイトルを取得します。2 番目の "for" ステートメントは、news.google.com の記事から送信時刻を取得します。

これはdjangoにあります。このページには、記事のタイトルのリストと、リストに提出された時間が下に向かって表示されます。2 番目の "for" ステートメント (時間の送信) から奇妙な Unicode 文字がポップアップしています。これが私のviews.pyです:

def articles(request):
""" Grabs the most recent articles from the main news page """
import bs4, requests

list = []
list2 = []
url = 'https://news.google.com/'
r = requests.get(url)
try:
    r.raise_for_status() == True
except ValueError:
    print('Something went wrong.')
soup = bs4.BeautifulSoup(r.text, 'html.parser')

for (listarticles) in soup.find_all('h2', 'esc-lead-article-title'):
    if listarticles is not None:
        a = listarticles.text
        list.append(a)

for articles_times in soup.find_all('span','al-attribution-timestamp'):
    if articles_times is not None:
        b = articles_times.text
        list2.append(b)

list = zip(list,list2)
context = {'list':list}

return render(request, 'newz/articles.html', context)
4

0 に答える 0