https://stackoverflow.com/a/64983/468251 - 您好,我对这段代码有疑问,如何使其与远程网站 url 一起使用,以及如何从所有输入中获取 value = fooId['value'],而不仅仅是从第一个输入?
最佳答案
当你解析互联网上的url时,你需要先找到一种方法来下载页面内容html。有一些很棒的库,比如 requests,据说最适合 python。假设您要解析 https://stackoverflow.com/
import requests
response = requests.get("https://stackoverflow.com/")
page_html = response.text
page_html是python字符串中的页面html,那么你可以将其视为本地html文件,并对它们进行任何类型的解析。
要获取某个模式的所有出现次数,您可以执行 soup.findAll('input',name='fooId',type='hidden')
,而不仅仅是 soup.find()
。 soup.findAll 将返回所有出现的列表。
关于python - 使用 Python BeautifulSoup 解析远程网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8837496/