当前位置 : 主页 > 编程语言 > python >

bs4爬虫

来源:互联网 收集:自由互联 发布时间:2022-06-15
#html标签的筛选 #拿到页面源代码 #使用bs4进行解析 import time import requests import csv from bs4 import BeautifulSoup header= { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko
#html标签的筛选

#拿到页面源代码
#使用bs4进行解析
import time
import requests
import csv
from bs4 import BeautifulSoup

header= {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36"
}
url="https://www.umeitu.com/bizhitupian/weimeibizhi/"
requ=requests.get(url)
print(requ.text)
time.sleep(0.5)

bs4是对hrml上相应标签内容进行查询,根据标签属性查找对应标签的内容

page=beautifulsoup(resp.text,"html.parser")

#find(标签,属性=值)

#find_all(标签,属性=值)

page.find("table",class_="属性值")




上一篇:爬虫xpath学习
下一篇:没有了
网友评论