首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python_Web_scraping Html表

Python_Web_scraping Html表
EN

Stack Overflow用户
提问于 2017-11-23 09:51:32
回答 1查看 63关注 0票数 0

我是Python初学者开发人员,我还在学习阶段。更具体地说,使用请求和bs4进行抓取。当尝试刮取以下链接时:“http://directorybtr.az.gov/listings/FirmSearchResults.asp?Zip%20Like%20%22850%25%22

我使用了以下代码:

代码语言:javascript
复制
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中检查源页面时该表是存在的。有什么解决办法或解释吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-24 21:57:58

表数据在帧内,你需要先走

代码语言:javascript
复制
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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47452397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档