简单爬虫

#!/usr/bin/python
# coding: UTF-8

import requests
from bs4 import BeautifulSoup
link="http://www.santostang.com/"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0'
}
r=requests.get(link,headers=headers)
soup=BeautifulSoup(r.text,"lxml")
title=soup.find("h1",class_="post-title").a.text.strip()
print(title)
with open('title.text',"a+") as f:
    f.write(title)
    f.close()

 

 

 

 

 

 

 

posted @ 2020-03-30 10:36  vcxvxcv  阅读(133)  评论(0)    收藏  举报