今日学习1.5小时
由于之前爬虫只是简单的运用与某个目的进行实现,具体内容不是很懂,这几天想着重学一下爬虫
通过网盘python学习看的视频来学习的
from fake_useragent import UserAgent import requests from lxml import etree url='https://www.qidian.com/rank/yuepiao/' headers={ "UserAgent":UserAgent().chrome } resp=requests.get(url,headers=headers) # print(resp.text) e=etree.HTML(resp.text) # print(etree.tostring(e).decode()) names=e.xpath('//div[@class="book-mid-info"]/h2/a/text()') print(names)
import re str='I study python3.6 eveyr_day' print("----------------------match()-----------------") m1=re.match(r'I',str) m2=re.search(r's\w+',str) m3=re.search(r'I (\w+)',str) m4=re.findall(r'p.+\d',str) print(m1) print(m2) print(m3) print(m4) s1=re.sub(r'e\w+',r'Everyday',str) print(s1)