网络爬虫基础练习
import requests
from bs4 import BeautifulSoup as bs
url = "http://news.gzcc.cn/html/2018/xiaoyuanxinwen_0329/9122.html"
res = requests.get(url).content.decode('utf-8')
soup = bs(res, 'html.parser')
h1 = soup.select('h1')[0].get_text()
print(h1)
a = soup.select('a')
for href in a:
print(href.get('href'))
li = soup.select('li')
for l in li:
print(l.get_text())
title = soup.select('title')
print(title)
url = 'http://news.gzcc.cn/html/xiaoyuanxinwen/'
res = requests.get(url).content.decode('utf-8')
soup = bs(res, 'html.parser')
h = soup.select('.news-list li a')
for i in h:
print(i[0].get('href'))
print(i[1].get_text())