日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python爬虫用到的一些东西

發布時間:2025/4/16 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python爬虫用到的一些东西 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原裝requests

>>> import requests
>>> response = requests.get('http://www.baidu.com')
>>> response.text 打印源代碼
>>> response.headers
{'Cache-Control': 'private, no-cache, no-store, proxy-revalidate, no-transform', 'Connection': 'Keep-Alive', 'Content-Encoding': 'gzip', 'Content-Type': 'text/html', 'Date': 'Mon, 26 Nov 2018 00:21:32 GMT', 'Last-Modified': 'Mon, 23 Jan 2017 13:28:36 GMT', 'Pragma': 'no-cache', 'Server': 'bfe/1.0.8.18', 'Set-Cookie': 'BDORZ=27315; max-age=86400; domain=.baidu.com; path=/', 'Transfer-Encoding': 'chunked'}
>>> response.status_code
200

>>> headers = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'}
>>> response = requests.get('http://www.baidu.com',headers=headers) 添加了header頭部

二進制文件的打印,圖片文件處理

>>> response = requests.get('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543204467171&di=19de509bd81641d74f3ac61472898d8e&imgtype=0&src=http%3A%2F%2Fimage.biaobaiju.com%2Fuploads%2F20180803%2F20%2F1533299921-zRLwijpYoE.jpg')
>>> response.content 輸出二進制文件
>>> with open('./1.jpg','wb') as f:
... f.write(response.content)

使用selenium模擬瀏覽器的操作

>>> from selenium import webdriver
>>> driver.get('http://m.weibo.cn') # 打開微博
>>> driver.get('http://www.zhihu.com') # 打開知乎
>>> driver.get('http://www.taobao.com') #打開淘寶
>>> driver.page_source #獲取網頁源代碼

轉載于:https://www.cnblogs.com/carious/p/10018428.html

總結

以上是生活随笔為你收集整理的python爬虫用到的一些东西的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。