【发布时间】:2015-10-22 04:59:18
【问题描述】:
我正在尝试使用 beautiful soup 4 来解析登录页面的 html 并从该页面获取令牌。
import requests
from bs4 import BeautifulSoup
session = requests.Session()
login_page_html = BeautifulSoup(session.get('https://url.com', verify=False).text)
lsd = value_from_name('something', login_page_html)
def value_from_name(name, soup):
return soup.find(name=name)['value']
我让它在另一个程序中工作,但我不确定为什么它不能在这里工作。我是 python 新手,猜是因为我没有正确传递参数?
【问题讨论】:
-
什么是
login_page_html? 不工作是什么意思? -
我的错,我不小心有 page_html = ... 而不是 login_page_html,它现在已在 OP 中修复。 @alecxe 感谢您的链接,以为我已经彻底搜索了答案,并且我认为在 python 中,您在调用它们之前或之后定义函数并不重要。
标签: python python-2.7 beautifulsoup html-parsing