問題:
UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently. The code that caused this warning is on line 10 of the file D:\python_work\test\test.py. To get rid of this warning, pass the additional argument 'features="html.parser"' to the BeautifulSoup constructor. noStarchSoup = bs4.BeautifulSoup(res.text)
解決方法:
noStarchSoup = bs4.BeautifulSoup(res.text,features='html.parser')
《CSS選擇器的例子》,select()方法將返回一個Tag對象的列表
| 傳遞給select()方法的選擇器 | 將匹配... |
| soup.select('div') | 所有名為<div>的元素 |
| soup.select('#author') | 帶有id屬性為author的元素 |
| soup.select('.notice') | 所有使用CSS class屬性名為notice的元素 |
| soup.select('div span') | 所有在<div>元素之內的<span>元素 |
| soup.select('div >span') | 所有直接在<div>元素之內的<span>元素,中間沒有其他元素 |
| soup.select('input[name]') | 所有名為<input>,並有一個name屬性,其值無所謂的元素 |
| soup.select('input[type="button"]') | 所有名為<input>,並有一個type屬性,其值為button的元素 |
