0
我正在研究一个项目,通过google新闻头条来查找关键字。如何使用python获取谷歌新闻标题和搜索关键字?
我希望它: -put的头条新闻到一个文本文件 -remove逗号,顿号,引号,标点符号等 - 搜索关键字
这是我到目前为止的代码。我得到的头条新闻,我现在只需要它来解析每个标题的关键字。
from lxml import html
import requests
# Send request to get the web page
response = requests.get('http://news.google.com')
# Check if the request succeeded (response code 200)
if (response.status_code == 200):
# Parse the html from the webpage
pagehtml = html.fromstring(response.text)
# search for news headlines
news = pagehtml.xpath('//h2[@class="esc-lead-article-title"] \
/a/span[@class="titletext"]/text()')
# Print each news item in a new line
print("\n".join(news))
这里的,例如,其中一个标题:'复杂化的“Brexit”计划,英国的高级特使欧盟Resigns' ...显示输出应该是什么样的解析后, – Andersson