python小白球解答,爬网页爬出来是空列表55555

初学python,有点懵懵的,照着代码抄都爬不出来,哭了呜呜呜

有大神能帮忙看一眼吗

 

就是一个简单的爬虫

from bs4 import BeautifulSoup
import requests

h= {'user-agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Mobile Safari/537.36' }

base_url="https://www.baidu.com/s?wd="
params=[
    "马保国",
    "周杰伦",
    "丁真",
]

results=[]

for param in params:
    pages=[10,20,30]
    temp=[]
    url=base_url+ param
    
    for page in pages:
        url = url +'&pn=' +str(20)
        res=requests.get(url, headers= h)
        res.encoding='utf-8'
        text=res.text
        soup=BeautifulSoup(text,'html.parser')
        sets=soup.find_all('h3',class_='t')
    
        for a in sets:
            temp.append(a.get_text())
    results.append(temp)


results
    

 

结果是这样滴~

[ [],[],[] ]

 

(第一次用CSDN不会上传截图......

查看全部
April1120
OhApril
2020/12/03 18:07
  • python
  • 点赞
  • 收藏
  • 回答
    私信

2个回复