【问题标题】:no module named 'bs4' error when compiled编译时没有名为“bs4”的模块错误
【发布时间】:2018-10-11 00:24:42
【问题描述】:

这演示了如何登录网站。它非常脆弱但 目标是演示如何处理表单、提交表单以及 使用会话来维护跨页面读取的 cookie 这个程序假设你已经完成了研究并且你知道什么 您需要填写的字段。

import sys
import requests
import lxml
import getpass
from bs4 import BeautifulSoup

sys.path.append("../lib")

from agentsGalore import agentsGalore
from formHelper import formHelper

开始一个会话 会话 = 请求。会话() ag = agentGalore()

def openURL(url,cookie=None):
global session
global ag
headers = ag.makeHeader("MacFirefox58","default","default","langUS")
try:
    if cookie:
        r = session.get(url, cookies=cookie, headers=headers)
    else:
        r = session.get(url, headers=headers)
 except requests.exceptions.RequestException as e:
    print(e)
    exit(1)

 return r

此函数使用哈希中的参数对 URL 进行 POST def postURL(网址,参数): 全球股份公司 全球会议 headers = ag.makeHeader("MacFirefox58","default","default","langUS") 尝试: r = session.post(url, data=params) 除了 requests.exceptions.RequestException 为 e: 打印(e) 退出(1)

return r

首先,打开登录页面

url = 'https://my.wlc.edu/ICS/'

resp = openURL(url)
fh = formHelper(resp.text)

得到一个填充的参数结构。您可以调用 fh.analyzeInputs() 来 查看所有输入字段是什么。

params = fh.populateFormInputs(fh.getFormById('MAINFORM'))

userid   = getpass.getpass("enter your userid:",sys.stderr)
password = getpass.getpass("enter your password:",sys.stderr)

params['userName'] = userid
params['password'] = password

formurl = 'https://my.wlc.edu/ICS/'
res = postURL(formurl,params)

【问题讨论】:

    标签: python beautifulsoup


    【解决方案1】:

    你可以尝试运行:

    apt-get install Python-bs4
    

    pip install beautifulsoup4
    

    easy_install beautifulsoup4
    

    在命令行中安装包beautifulsoup4。

    【讨论】:

    • 我在学校的电脑上,所以我没有管理员权限。我目前在虚拟环境中
    • @Ty'TeonnaFranklin 你用的是virtualenv还是虚拟机?
    • Virtualenv 抱歉
    • @Ty'TeonnaFranklin try: source env_path/bin/activate 进入虚拟环境,然后可以使用pip在virtualenv中安装包。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-30
    • 2015-01-19
    • 2021-04-02
    • 2020-10-28
    • 2019-09-29
    • 2013-02-11
    • 2020-12-03
    相关资源
    最近更新 更多