1.re正则表达式
# 正则表达式分析: 找开始和结束标签,两个标签之间把想要的内容需要包含进来,然后依次查找分析。
pat = r'<div class="post floated-thumb">(.*?)<p class="align-right"><span class="read-more">'
# 使用findall方法查找符合要求的全部内容,放置到一个列表
divlist = re.findall(pat,HTML,re.S) #re.S : 是.匹配包括换行之内的所有字符
2.xpath(scrapy自带的)
next=response.xpath("//li[@class='next']/a/@href").extract()[0]
extract(): 序列化该节点为unicode字符串并返回list。
3.bs4
bsoup = BeautifulSoup(dataopen, "html.parser")
datas = bsoup.find_all("div", {"class":"reveal-work-wrap"}) #获取所有这个标签,再遍历解析 for x in datas: print(x) childimg = x.find("img").get("src") pathpic1 = childimg.split("/")[-1] filepath1 = os.path.join("D:\putweb", pathpic1) urllib.request.urlretrieve(childimg,filepath1)