Как получить конкретное значение c, используя python запросы? - PullRequest
1 голос
/ 13 января 2020

Я пытаюсь проанализировать этот сайт https://www.5dimes.eu/ и извлечь из него указанное значение c. как показано на рисунке, но это вовсе не заполняется запросом get. Но я могу видеть это, когда открываю браузер. enter image description here

Я просто получаю вывод, как показано ниже.

import requests
import json
from bs4 import BeautifulSoup
import time
t = requests.get("https://www.5dimes.eu/")
soup = BeautifulSoup(t.content)
print(soup.find_all('td'))


<td align="center" colspan="3"><input class="login" id="customerID" maxlength="50" name="customerID" type="text"/></td>
</tr>
<tr valign="middle">
<td align="center" colspan="3" height="20" valign="bottom">Password</td>
</tr>
<tr>
<td colspan="3" height="1"><img alt="5Dimes Sportsbook - Casino - Racebook - Lottery - Poker" border="0" height="1" src="images/trans.gif" title="5Dimes Sportsbook - Casino - Racebook - Lottery - Poker" width="1"/></td>
</tr>
<tr valign="middle">
<td align="center" colspan="3"><input autocomplete="off" class="login" maxlength="50" name="password" type="password"/>
<input id="ioBB" name="ioBB" type="hidden"/>
</td>

Ответы [ 2 ]

2 голосов
/ 13 января 2020
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from bs4 import BeautifulSoup

options = Options()
options.add_argument('--headless')

driver = webdriver.Firefox(options=options)
driver.get("https://www.5dimes.eu/")

soup = BeautifulSoup(driver.page_source, 'html.parser')

val = soup.find("input", {'id': 'ioBB'}).get("value")

print(val)
driver.quit()

enter image description here

0 голосов
/ 13 января 2020

Нашел решение, используя запросы_ html.

Вот код.

import requests
import json
from bs4 import BeautifulSoup
import time


from requests_html import HTMLSession

session = HTMLSession()

r = session.get("https://www.5dimes.eu/", headers={'User-Agent': 'Mozilla/5.0'})
r.html.render()
print(r.html.html)
...