亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何在python中添加'features="html.parser"'

如何在python中添加'features="html.parser"'

神不在的星期二 2021-11-09 15:37:54
我有一些返回錯誤的代碼:UserWarning:沒有明確指定解析器,所以我使用了這個系統最好的可用 HTML 解析器(“html.parser”)。這通常不是問題,但如果您在另一個系統上或在不同的虛擬環境中運行此代碼,它可能會使用不同的解析器并表現出不同的行為。導致此警告的代碼位于文件 scrape7.py 的第 14 行。要消除此警告,請將附加參數 'features="html.parser"' 傳遞給 BeautifulSoup 構造函數。我的代碼是:import numbersimport httplib2import requestsimport refrom bs4 import BeautifulSoup, SoupStrainerhttp = httplib2.Http()status, response = http.request('https://www.macys.com/social/the-edit/')editurlslist = []for link in BeautifulSoup(response, parse_only=SoupStrainer('a')):    if link.has_attr('href'):        if '/the-edit' in link['href']:            editurlslist.append(str("https://www.macys.com"+link['href']))products = []for i in editurlslist:   products.append(re.findall(r'(data-thisProduct=\"[0-9]{7}\")',    requests.get(i).text))for i in editurlslist:   products.append(re.findall(r'(productid=\"[0-9]{7}\")',    requests.get(i).text))products2 = [x for x in products if type(x) in numberic_types]print(products2)
查看完整描述

1 回答

?
喵喵時光機

TA貢獻1846條經驗 獲得超7個贊

將“html.parser”參數傳遞給 BeautifulSoup 構造函數:

for link in BeautifulSoup(response, "html.parser", parse_only=SoupStrainer('a')):


查看完整回答
反對 回復 2021-11-09
  • 1 回答
  • 0 關注
  • 490 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號