python代码
这是要获取的信息
内容目录
-
源代码
- 需要提前安装好几个包 输出
- 输出显示到屏幕
1、源代码
import requests
from bs4 import BeautifulSoup
url = '链接'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
'Connection': 'keep-alive'
}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
results = soup.find_all('div', class_='gs_r gs_or gs_scl')
for result in results:
title = result