import requests
from bs4 import BeautifulSoup
def fetch_google_trending_news():
url = "https://trends.google.com/trends/trendingsearches/daily?geo=US"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
news_items = soup.find_all('div', class_='title')
for index, item in enumerate(news_items, 1):
news_title = item.text.strip()
print(f"{index}. {news_title}")
else:
print("Failed to fetch trending news.")
if __name__ == "__main__":
fetch_google_trending_news()
08-26
544
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-12
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交