import requests
from bs4 import BeautifulSoup
s=requests.session()
r=s.get("http://news.ifeng.com/listpage/11502/20181007/1/rtlist.shtml")
body=r.content.decode()
soup=BeautifulSoup(body,'lxml')
rs1=soup.find(class_="newsList")
rs2=rs1.find_all('a',target="_blank")
for item in rs2:
print(item.attrs["href"])
print(item.string)
print(rs1)
其他的常用方法
print(a.attrs["id"])
r=soup.find(id="link2")
print(r.string)
gl=item.contents[7].text.split('|')[1]
price=item.content[9].contents[3].text
网友评论