1. 程式人生 > >《Forward團隊-爬蟲豆瓣top250項目-開發文檔》

《Forward團隊-爬蟲豆瓣top250項目-開發文檔》

attrs -a exce turn 獲取網頁 nbsp head 碼雲 all

碼雲地址:https://技術分享github.com/xyhcq/top250

模塊功能:獲取豆瓣top250網頁的源代碼,並分析。

def getHTMLText(url,k):
    # 獲取網頁源代碼
    try:
        if(k==0):
            kw={}
        else:
            kw={start:k,filter:‘‘}
        # 保存獲取的網頁
        read = requests.get(url,params=kw,headers={User-Agent: Mozilla/4.0})
        read.raise_for_status()
        read.encoding 
= read.apparent_encoding return read.text except: print("獲取失敗!") def getData(html): # 分析代碼信息,提取數據 soup = BeautifulSoup(html, "html.parser") # 找到第一個class屬性值為grid_view的ol標簽 movieList=soup.find(ol,attrs={class:grid_view}) # 找到所有的li標簽 for movieLi in movieList.find_all(
li): # 找到第一個class屬性值為hd的div標簽 movieHd=movieLi.find(div,attrs={class:hd})

《Forward團隊-爬蟲豆瓣top250項目-開發文檔》