python 爬取网页
【摘要】
pip install Beautifulsoup4
from bs4 import BeautifulSoupimport requestsif __name__=='__main__': target='http://www.luoxia.com/daqindiguo/84575.htm' #kv = {'user-agent...
pip install Beautifulsoup4
-
-
from bs4 import BeautifulSoup
-
import requests
-
if __name__=='__main__':
-
target='http://www.luoxia.com/daqindiguo/84575.htm'
-
#kv = {'user-agent': 'Mozilla/5.0'}
-
try:
-
req=requests.get(url=target)
-
html=req.text
-
bf=BeautifulSoup(html,"lxml")
-
texts=bf.find_all('div',id="nr1")
-
-
aaa=texts[0].text.replace('\xa0','')
-
bbb=aaa.replace("\n\n","")
-
print(bbb)
-
except Exception as e:
-
print("爬取异常",e)
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/89462976
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)