找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2991|回复: 3

[求助] 爬虫问题

回帖奖励 10 点威望 回复本帖可获得 10 点威望奖励! 每人限 4 次(中奖概率 90%)

15

主题

31

帖子

31

积分

贫民

积分
31
benson 发表于 2020-11-22 11:59:44 | 显示全部楼层 |阅读模式
源代码:
import requests
from bs4 import BeautifulSoup
url="https://fs.lianjia.com/zufang/"
r=requests.get(url)
print(r)
print(r.text)
s=BeautifulSoup(r.text)
print(s,"html.parser")
s.find_all("div",class_="")

错误:
Warning (from warnings module):
  File "C:\Users\Administrator\Desktop\python\11.21 01.py", line 7
    s=BeautifulSoup(r.text)
GuessedAtParserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 7 of the file C:\Users\Administrator\Desktop\python\11.21 01.py. To get rid of this warning, pass the additional argument 'features="html.parser"' to the BeautifulSoup c**tructor.

回复

使用道具 举报

15

主题

31

帖子

31

积分

贫民

积分
31
benson  楼主| 发表于 2020-11-22 12:15:01 | 显示全部楼层
对不起,发错了
回复 支持 反对

使用道具 举报

15

主题

31

帖子

31

积分

贫民

积分
31
benson  楼主| 发表于 2020-11-22 12:25:11 | 显示全部楼层
这个才是
源代码:
import requests
from bs4 import BeautifulSoup
url="https://dg.lianjia.com/"
r=requests.get(url)
print(r)
print(r.text)
s=BeautifulSoup(r.text,"html.parser")
print(s,"html.parser")
s.find_all("div",class_="")
s.find_all("div",class_="pic-panel")
links_div=s.find_all("div",class_="pic-panel")
links=[div.a.get("href") for div in links_div]
print(links)
为什么结果是[]?

回复 支持 反对

使用道具 举报

0

主题

956

帖子

956

积分

圣骑士

积分
956
sheeboard 发表于 2020-11-23 11:02:21 | 显示全部楼层

回帖奖励 +10 点威望

找不到class_="pic-panel"
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表