Python запрос на изменение языка - PullRequest
0 голосов
/ 16 июня 2020

Как я могу получить страницу с другим языком не по умолчанию

Мой код:

import requests
from bs4 import BeautifulSoup


def scrap(page):
    url = page
    result = requests.get(url, stream=True)
    if result.status_code == 200:

        soup = BeautifulSoup(requests.get(url).content, 'html.parser')
        return soup

product=scrap("https://www.tatechnix.de/tatechnix/gx/product_info.php?info=p44232")

print(product)

и теперь, когда я открываю эту страницу, я получаю DE lang, как я могу получить его с EN lang ?

У них нет другого URL-адреса или префикса для языка. Изменения только в кнопке.

Изменить:

import re
import requests
from bs4 import BeautifulSoup


def scrap(page):
    headers = {'Accept-Language': 'en-US,en;q=0.8'}
    url = page
    result = requests.get(url, stream=True)
    if result.status_code == 200:
        getPage= requests.get(url, headers=headers)
        soup = BeautifulSoup(getPage.content, 'html.parser')

        title=soup.select('.product-info-title-desktop')[0].text
        return title

product=scrap("https://www.tatechnix.de/tatechnix/gx/product_info.php?info=p44232")

print(product)

Ничего не изменилось: /

1 Ответ

1 голос
/ 16 июня 2020

Попробуйте:

import re
import requests
from bs4 import BeautifulSoup


def scrap(page):
    url = page
    result = requests.get(url, stream=True)
    if result.status_code == 200:
        getPage= requests.get(url)
        soup = BeautifulSoup(getPage.content, 'html.parser')

        title=soup.select('.product-info-title-desktop')[0].text
        return title

product=scrap("https://www.tatechnix.de/tatechnix/gx/product_info.php?info=p44232&language=en")

print(product)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...