Python:告诉BeautifulSoup' IF'找不到值,重试

时间:2018-02-27 22:32:12

标签: python web-scraping beautifulsoup

我仍然是python的初学者,我想抓一个网站,我希望Python搜索一个值直到它可见,因此重试直到值可用而不是给出错误' AttributeError: '结果集'对象没有属性' get'如果没有找到值。这是我现在的代码:

resumeURL='url'
response=self.session.get(resumeURL,headers=headers)
soup=BeautifulSoup(response.content, "html.parser")

form=soup.find_all('input',{'name':'form_id', 'type':'hidden'})
for form in form:
print(form.get('value'))

1 个答案:

答案 0 :(得分:0)

您必须呈现动态内容。

选项:

  1. selenium,https://github.com/SeleniumHQ/selenium
  2. 请求-HTML:针对人类的HTML解析,https://github.com/kennethreitz/requests-html#requests-html-html-parsing-for-humans