爬蟲(一) 用Requests模組獲取網頁資訊

2021-08-19 19:21:11 字數 1028 閱讀 5082

呼叫requests庫裡面的get方法,獲取網頁的資訊,呼叫page.text獲取網頁原始碼,然後通過print列印出網頁原始碼
importrequests

page = requests.get('')

text = page.text

print(text.encode("utf-8"))

importrequests

importre

head =

timeout = 30

defrequestpagetext(url):

try:

page = requests.session().get(url, headers=head, timeout=timeout)

page.encoding ="gb2312"returnpage.text

exceptbaseexception

ase:

print("聯網失敗了...", e)

site =""text = requestpagetext(site) # 抓取網頁原始碼

patterns = re.compile(r'http:.*?/\d*?.html') # 匹配需要的資料

istp = re.findall(patterns, text)

forphotoinistp:

print(photo)

python爬蟲requests模組

首先,沒有安裝的先安裝 cmd pip conda install requests 先給大家乙個模板,如果已經很熟悉了,直接忽略,不懂得就可以看看了 接下來解釋一下相應的 的意思 這個和上和上面的是一樣的,執行後輸出的 都是一樣的啦 coding utf 8 引入網路請求模組,該模組有兩個重要的物...

python爬蟲 requests模組

功能 模擬瀏覽器發請求 指定url 發起請求 獲取響應資料 持久化儲存 import requests 指定url url 發起請求,返回乙個響應對像 response requests.get url url 獲取響應資料 text返回的是字串型別的響應資料 page text response....

爬蟲之requests模組

requests 唯一的乙個非轉基因的 python http 庫,人類可以安全享用。警告 非專業使用其他 http 庫會導致危險的 包括 安全缺陷症 冗餘 症 重新發明輪子症 啃文件症 抑鬱 頭疼 甚至死亡。今日概要 知識點回顧 為什麼要使用requests模組 使用requests模組 如何使用...