嗨,我是用下面的代码来报废克雷格利斯特的。你知道吗
import pandas as pd
import requests
%pylab inline
url_base = 'http://houston.craigslist.org/search/apa'
params = dict(bedrooms=2)
rsp = requests.get(url_base, params=params)
print(rsp.text[:500])
from bs4 import BeautifulSoup as bs4
html = bs4(rsp.text, 'html.parser')
print(html.prettify()[:1000])
到目前为止一切正常,输出为:-
<!DOCTYPE html>
<html class="no-js">
<head>
<title>
houston apartments / housing rentals - craigslist
</title>
<meta content="houston apartments / housing rentals - craigslist"
name="description">
<meta content="IE=Edge" http-equiv="X-UA-Compatible"/>
<link href="https://houston.craigslist.org/search/apa" rel="canonical">
<link href="https://houston.craigslist.org/search/apa?
format=rss&min_bedrooms=2" rel="alternate" title="RSS feed for
craigslist | houston apartments / housing rentals - craigslist "
type="application/rss+xml">
<link href="https://houston.craigslist.org/search/apa?
s=120&min_bedrooms=2" rel="next">
<meta content="width=device-width,initial-scale=1" name="viewport">
<link href="//www.craigslist.org/styles/cl.css?
v=a14d0c65f7978c2bbc0d780a3ea7b7be" media="all" rel="stylesheet"
type="text/css">
<link href="//www.craigslist.org/styles/search.css?v=27e1d4246df60da5ffd1146d59a8107e" media="all" rel="stylesheet" type="
它清楚地表明列表不是空的,并且有一些项目我可以使用。这是使用以下代码:-你知道吗
apts = html.find_all('p', attrs={'class': 'row'})
print(len(apts))
上述打印输出(len(apts))为0。。 有人能帮忙改正这个密码吗。我确实相信craiglisthtml解析器有一些变化,但我不知道如何在这里实现它。你知道吗
谢谢
没有带有
'row'
类的<p>
标记,而<p>
具有'result-info'
类。你知道吗相关问题 更多 >
编程相关推荐