我是Python初学者开发人员,我还在学习阶段。更具体地说,使用请求和bs4进行抓取。当尝试刮取以下链接时:“http://directorybtr.az.gov/listings/FirmSearchResults.asp?Zip%20Like%20%22850%25%22”
我使用了以下代码:
import requests
from bs4 import BeautifulSoup
url ="http://directorybtr.az.gov/listings/FirmSearchResults.asp?Zip%20Like%20%22850%25%22"
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
res.close()
results = soup.find('table')结果中没有表格,尽管在Chrome中检查源页面时该表是存在的。有什么解决办法或解释吗?
谢谢
发布于 2017-11-24 21:57:58
表数据在帧内,你需要先走
import requests
from lxml import html
from bs4 import BeautifulSoup
BASE_URL = "http://directorybtr.az.gov/listings/"
URL = BASE_URL + "FirmSearchResults.asp?Zip%20Like%20%22850%25%22"
#u need session because the frame use the search results data, u cant directly go to Firms.asp
session = requests.session()
response = session.get(URL)
soup = BeautifulSoup(response.text, 'lxml')
#find the first frame
frame = soup.find("frame")
#go to the frame link ( Firms.asp )
response = session.get(BASE_URL + frame.attrs['src'])
soup = BeautifulSoup(response.text, 'lxml')
table = soup.find("table")
print table
response.close()https://stackoverflow.com/questions/47452397
复制相似问题