第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

網(wǎng)絡(luò)數(shù)據(jù)采集的例子,有關(guān)find函數(shù)等等的疑問

網(wǎng)絡(luò)數(shù)據(jù)采集的例子,有關(guān)find函數(shù)等等的疑問

幕布斯6054654 2019-02-25 21:48:08
來自 Python網(wǎng)絡(luò)數(shù)據(jù)采集的例子: from urllib.request import urlopen from bs4 import BeautifulSoup import datetime import random import re random.seed(datetime.datetime.now()) def getLinks(articleUrl): html = urlopen("http://en.wikipedia.org"+articleUrl) bsObj = BeautifulSoup(html) return bsObj.find("div", {"id":"bodyContent"}).findAll("a", href=re.compile("^(/wiki/)((?!:).)*$")) links = getLinks("/wiki/Kevin_Bacon") while len(links) > 0: newArticle = links[random.randint(0, len(links)-1)].attrs["href"] print(newArticle) links = getLinks(newArticle) 問題一: return bsObj.find("div", {"id":"bodyContent"}).findAll("a", href=re.compile("^(/wiki/)((?!:).)*$")) 這段代碼里面, find函數(shù)后面為什么可以加findAll,即寫成 XXX.find().findAall() 的形式? 問題二:newArticle = links[random.randint(0, len(links)-1)].attrs["href"]此段代碼 像 links[].attrs[] 之類的寫法是如何依據(jù)的?可以這樣寫的原理? 新人求教~~謝謝!
查看完整描述

2 回答

?
有只小跳蛙

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超8個贊

find函數(shù)返回的也是html文檔,可以接find函數(shù)和find_all函數(shù);
數(shù)組取值后可以直接當(dāng)作值的元素對待,例如:

a = ['ab',1,[1,2]]
a[0].upper() # 'AB'
a[2].append(1) # a == ['ab',1,[1,2,1]]
查看完整回答
反對 回復(fù) 2019-03-04
  • 2 回答
  • 0 關(guān)注
  • 548 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號