【发布时间】:2016-07-18 04:18:57
【问题描述】:
我使用 python 为 2 个不同的 url 编写了一个抓取脚本
http://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA
对于第一个网址,我编写了以下脚本
import requests
from bs4 import BeautifulSoup
url = requests.get("http://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los%20Angeles%2C%20CA")
url.content
soup = BeautifulSoup(url.content)
print (soup.prettify())
g_data = soup.find_all("div", {"class": "info"})
for item in g_data:
print (item.contents[0].find_all("a", {"class": "business-name"})[0].text)
它打印了企业名称中的所有文本。但是,当我对第二个 url 使用相同结构但不同的脚本时,它会获取 url 内容,但不像第一个 url 那样从页面中获取全部内容。
第二个网址脚本
import requests
from bs4 import BeautifulSoup
url = requests.get("http://www.yellowpages.com.au/search/listings?clue=concrete+contractors&locationClue=nsw+australia&lat=&lon=&selectedViewMode=list")
url.content
soup = BeautifulSoup(url.content)
print (soup.prettify())
g_data = soup.find_all("div", {"class": "body left"})
for item in g_data:
print (item.contents[0].find_all("a", {"class": "listing-name"})[0].text)
我的问题是为什么它不能作为第一个脚本并且没有给出企业名称
【问题讨论】:
标签: python beautifulsoup