'Python printing weird characters [closed]
I'm running Windows 11, with the output in Windows Terminal
from gnewsclient import gnewsclient
import requests
print("requesting google news...")
news_list = gnewsclient.NewsClient('english', 'entertainment', 'US', 10).get_news()
item = news_list[0]
print("extracting text from web page...")
title = item['title'].rpartition(' - ')[0]
print(title)
print(item['link'])
output:
requesting google news...
extracting text from web page...
ภาวะตลาดหุ้นไทย: ดิ่ง 28.82 จุด ตามตลาดหุ้นโลกผวาเงินเฟ้อสหรัฐพุ่ง-กังวล MSCI - อาร์วายที9
https://news.google.com/__i/rss/rd/articles/CBMiI2h0dHBzOi8vd3d3LnJ5dDkuY29tL3MvaXEwNS8zMzIxNzcx0gEA?oc=5
Does anyone know how to correct this text?
Solution 1:[1]
The problem here is the order of the parameters. You should read the code. It wants location, then language, then topic. So, you're not telling it to send English. This is why the documentation suggests using named parameters.
news_list = gnewsclient.NewsClient(language='english', topic='entertainment', location='US', max_results=10).get_news()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tim Roberts |
