python获取网页,匹配指定行

from urllib.request import urlopen, Request
import re

''' 获取网页,匹配指定行 '''
url = 'https://www.wangdun.cn/gfserver/'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'}
ret = Request(url, headers=headers)
responses = urlopen(ret).readlines()
a = '<span class="price_2">'
for i in responses:
y = i.decode('gbk')
if a in y:
print(y)

 

posted @ 2021-12-14 09:34  不爱缺氧i  阅读(127)  评论(0)    收藏  举报