python - Python - 查看机器人?
问题描述
我正在尝试为 viewbot 编写一些代码。
代码:
import requests
from bs4 import BeautifulSoup
import html5lib
import urllib
import argparse, os, time
import urllib.parse, random
headers = {
'user-agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Mobile Safari/537.36'
}
login_data = {
'login': 'xxx',
'pass': 'xxx',
'back_url': ''
}
现场登录正常工作。
列出人员:
def getPeopleLinks(page):
links = []
for link in soups.find_all('a'):
url = link.get('href')
if url:
if 'profile/' in url:
links.append(url)
return links
在职的...
和其他代码:
with requests.Session() as session:
url = "https://xxxxxx.com/Login/?form_login=1"
post = session.post(url, data=login_data, headers=headers)
print (post.status_code)
print (post.cookies)
r = session.get("https://xxxxxxx.com/online/GIRL")
print (r.status_code)
print (r.cookies)
soups = BeautifulSoup(r.content, 'html5lib')
x = getPeopleLinks(soups)
print(x)
print("http://www.xxxxx.com"+ x[2])
for link in x:
urllib.request.urlopen("http://www.xxxxxxx.com"+link)
print(link)
登录:正常工作。
在线用户列表:正常工作;我得到所有配置文件列表。
我认为这是一个问题:
for link in x:
urllib.request.urlopen("http://www.xxxxxxx.com"+link)
print(link)
我通过手机登录了另一个帐户,我的个人资料在列表中,但 PC 上的机器人没有查看我的个人资料。
解决方案
这是因为url的语法有问题。或者可能是因为此特定代码中可能存在问题,请尝试以下操作:
import urllib.request
for path in paths:
url = 'http://example.com/view-online-profiles/' + path
page = urllib.request.urlopen(url)
print(page.read())
或者你也可以按照另一种方式:
import requests
for path in paths:
url = 'http://example.com/view-online-profiles/' + path
page = requests.get(url)
print(page) # Would return response object, can obtain status_code or body
推荐阅读
- android - Android BottomNavigationView 在被删除/隐藏后留下空白
- sql - 在.net core 3.0 中是否为使用 Azure Key Vault 始终加密的 SQL 提供了适当的支持?
- linux - 如何模拟挂起的文件系统?
- c# - 如何在 C# 中将数据从指针复制到指针?
- javascript - SVG 图表 - 我如何调整 svg 的高度,以便所有标签自动适合里面
- regex - 有效 WKT 线串的正则表达式(在 BigQuery 中)?
- asp.net - Visual Studio 2019 占用大量 CPU 并非常缓慢地为简单的 asp.net 提供服务
- java - 如何针对数据库数据验证 Jmeter JSON 响应
- mysql - mysql phpmyadmin 中的存储过程 #1064
- python - 我无法在更大的字符串中找到我的子字符串