如何从网址列表(或字符串)中获取标题?

时间:2019-04-18 19:18:28

标签: python-3.x

我已经解析了Google搜索中的一些链接,现在无法从中获取标题。我如何在python 3(mac os)上做到这一点。我知道beautifulsoap和lxml,但是我没有设法在代码中使用它们。

from requests_html import HTMLSession

keyword = input('Type keyword: ')

session = HTMLSession()
r = session.get(f'https://www.google.com/search?q={keyword}&num=100&hl=en')

links = r.html.xpath('//div[@class="r"]/a[1]/@href') #get the list of urls

a = links[ :11] #get 10 urls from the list

string = '\n'.join(a) #make a string from the list 

下一步是什么?

0 个答案:

没有答案