0

The starting URL of a web application is "https://ts15.travian.co.il". When clicking on an attribute in the game it takes you to "https://ts15.travian.co.il/build.php?id=35", but when i try to assign the URL to the code and open it it goes nack to the 'sign in page'.

I've already tried clicking on the attribute but it only worked for me with selenium and i don't want to open an actual browser. When i sign-in to the game myself i can enter the URL of the attribute and it will take me there but with the code it doesn;t work

import requests
from bs4 import BeautifulSoup

login_data = dict(name='SomeUserName', password='SomePassWord')

URL = 'https://ts15.travian.co.il'
travian_logIn = requests.post(URL, data=login_data, headers=myUserAgent)

URL_attribute = 'https://ts15.travian.co.il/build.php?id=35'
source_of_builds = requests.get(URL_attribute, headers=myUserAgent)
soup02 = BeautifulSoup(source_of_builds.content, 'lxml')
print(soup02)

When printing the content with BeautifulSoup i got the same content as the "Log-In" URL

source = requests.get(URL, headers=myUserAgent)
print(BeautifulSoup(source.content, 'lxml'))

=======

source_of_builds = requests.get(URL_attribute, headers=myUserAgent)
print(BeautifulSoup(source_of_builds.content, 'lxml'))


Tomer Bachar
  • 11
  • 1
  • 2
  • 1
    try having a look at [this solution](https://stackoverflow.com/questions/15778466/using-python-requests-sessions-cookies-and-post) – chitown88 Sep 12 '19 at 15:46

1 Answers1

0

Try using a requests session so that the website can remember you logged in.

import requests
from bs4 import BeautifulSoup

login_data = dict(name='SomeUserName', password='SomePassWord')

URL_main = 'https://ts15.travian.co.il/login.php'
URL_attribute = 'https://ts15.travian.co.il/build.php?id=35'

s = requests.Session()
s.headers = myUserAgent
s.get(URL_main)
travian_logIn = s.post(URL_main, data=login_data)
source_of_builds = s.get(URL_attribute)

soup02 = BeautifulSoup(source_of_builds.content, 'lxml')
print(soup02)
LuckyZakary
  • 1,171
  • 1
  • 7
  • 19