【python爬虫】第一次用python写爬虫啦!
selenium用起来真的很方便~但是每次都要打开浏览器大量采集可能会有麻烦from selenium import webdriver
import requests
import bs4
browser = webdriver.Chrome()
browser.get("https://voice.baidu.com/act/newpneumonia/newpneumonia/?from=osari_pc_3")
soup = bs4.BeautifulSoup(browser.page_source, "html.parser")
targets = soup.select("#nationTable tr.VirusTable_1-1-257_3m6Ybq")
for each in targets:
info=""
targets2=each.select("span")
info+=targets2[1].text+" "
targets3=each.select("td.VirusTable_1-1-257_3x1sDV.VirusTable_1-1-257_2bK5NN")
info+=targets3[0].text+" "
targets4=each.select("td.VirusTable_1-1-257_3x1sDV")
info+=targets4[1].text+" "
info+=targets4[2].text+" "
targets5=each.select("td.VirusTable_1-1-257_EjGi8c")
info+=targets5[0].text+" "
info+=targets5[1].text+" "
print(info)
|