Python - 查看机器人?

问题描述 投票:0回答:2

我正在尝试为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上的机器人没有查看我的个人资料。

python web login urllib2
2个回答
0
投票

这是因为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

0
投票

这很大程度上取决于平台如何计算视图。在现代网络应用程序的情况下,它不是关于HTTP请求的可能性高,而是花费在浏览器活动上的时间,通过页面上的JS代码进行跟踪。

© www.soinside.com 2019 - 2024. All rights reserved.