我有一些返回錯誤的代碼: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')):
添加回答
舉報
0/150
提交
取消