1. 程式人生 > >python使用requests庫爬取網頁的小實例:爬取京東網頁

python使用requests庫爬取網頁的小實例:爬取京東網頁

try Coding get 代碼 cep .get style ppa print

爬取京東網頁的全代碼:

#爬取京東頁面的全代碼
import requests
url="https://item.jd.com/2967929.html"
try:
    r=requests.get(url)
    r.raise_for_status()
    r.encoding=r.apparent_encoding
    print(r.text[:1000])
except:
    print("爬取失敗")

python使用requests庫爬取網頁的小實例:爬取京東網頁