记一次极其艰难的爬虫作业

最最最开始,我内心很淡定,词云都做了,这些都是毛毛雨啦~然后,生活就狠狠地打了我的脸……爬不出来,各种各样形形色色的奇怪问题都出来了,最终出来了结果(爬文章比爬网页要容易)下面就是代码:

import requests
from bs4 import BeautifulSoup
url="http://politics.gmw.cn/2020-05/03/content_33801674.htm"
r=requests.get(url)
r.raise_for_status()
r.encoding=r.apparent_encoding
txt=r.text
ls = []
soup = BeautifulSoup(txt,"html.parser")
for tag in soup.find_all('p'):
ls.append(tag)
print(ls)

然后就爬出来了

猜你喜欢

转载自www.cnblogs.com/eveya/p/12822648.html