网页爬虫
 
import requests
from bs4 import BeautifulSoup


from urllib import request;

headers = {
	'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
}


if __name__ == '__main__':
    
    url = 'https://xjiejie.vip/'
    try:
        #请求地址
        resp = requests.get(url,headers = headers)
        
        #获取到网页text
        html = resp.text
        
        #res.text是源网页的html,第二个参数'html.parser'是使用html的剖析器
        soup = BeautifulSoup(html, 'html.parser')
        
        #使用select函数找出所有含有特定CSS属性的和html标签元素
        h1 = soup.select('video')
        
        video = soup.select('video')[0]['src'];
        
        
        path = "C:/Users/tongyao/Desktop/爬网页/file/sp.mp4"
        
        #模拟浏览器请求
        req = request.Request(video);

        req.add_header('User-Agent','Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36');

        response = request.urlopen(req).read();

        with open(path,'wb') as f:

         f.write(response);
        print("完成")
            
            
        #for h in h1:
        #    print(h[0])
        
        #a = '<a href = "#" abc = 456 def = 123> i am a link </a>'
        #soup = BeautifulSoup(a, 'html.parser')
        #print(soup.select('a')[0]['href'])#输出"#"
        #print(soup.select('a')[0]['abc'])#输出"456"
        #print(soup.select('a')[0]['def'])#输出"123"
        
        
        #path = "C:/Users/tongyao/Desktop/爬网页/file/1.html"
        ## 将他拷贝到本地文件 w 写  b 二进制  wb代表写入二进制文本
        #with open(path, 'wb') as f:
        #    f.write(html)
        
    except Exception as e:
        print('出异常了,异常为:'+str(e))
    input()
来做第一个评论吧!~

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇