#coding:utf-8? #設(shè)置文本格式
import requests? # 引入request庫(kù)
from bs4 import? BeautifulSoup
url = 'http://news.qq.com'
wbdata = requests.get(url).text? ? ? #request.get方法獲取url
soup = BeautifulSoup(wbdata,'lxml')??
news_titles = soup.select('div > div > em > a')? 獲取select 的路徑?
for n in news_titles:? # news_titles 循環(huán)?
? ? ? ? title = n.get_text()
? ? ? ? link = n.get('href')
? ? ? ? data = {
? ? ? ? ? ? '標(biāo)題':title,
? ? ? ? ? ? '鏈接':link,
? ? ? ? }
? ? ? ? print(data)? #數(shù)據(jù)打印出來(lái)?