Python网站登录和xpath [英] Python website login and xpath

查看:93
本文介绍了Python网站登录和xpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手,我正尝试登录一个网站并收集一个对象.认证页面首先出现,然后进入该页面,但是,我无法进行认证.

I'm new at programming and I was trying to login into a website and gather an object. The authentication page comes up first, then it goes to the page, however, I'm not able to authenticate.

from lxml import html

import requests

session = requests.Session()

response = session.get('https://123.com/auth?name=ABC&pw=ABC')

page = requests.get('123.com')
tree = html.fromstring(page.content)

alert = tree.xpath('//*[@id="casealertsdataview"]/div')

print (alert)

推荐答案

首先,尝试下面的代码,看看它是否成功且没有错误.
然后您就可以开始处理有效载荷了.

First, try the below code, and see if it succeed without errors.
Then you could start processing the payload.

#!/usr/bin/env python

from __future__ import print_function
from pprint import pprint
import requests
from sys import exit

user = 'ABC'
pw = 'ABC'

r = requests.get('https://123.com/', auth=('user', 'pw'))
r = requests.get(URL)

if r.status_code != 200:
    exit(r.status_code)

exit(r.status_code)

这篇关于Python网站登录和xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆