1

Имеется код:

from bs4 import BeautifulSoup
from urllib.request import urlopen
import requests
def Proxy ():


    pars()
def  pars ():
    url = 'http://www.gatherproxy.com/ru/sockslist'
    try:

     soup = BeautifulSoup(urlopen(url).read(), 'html.parser')
    except:
        return 0

    td = soup.find('table', id='tblproxy').find_all('td')

    print(td)


Proxy()

Мне нужно получить тег script, но find_all не помогает, что делать?

2
  • 1
    soup.find_all('script') пробовали?
    – floydya
    Commented 10 окт. 2018 в 18:12
  • да , не помогло
    – dark0ghost
    Commented 11 окт. 2018 в 11:08

1 ответ 1

2
from bs4 import BeautifulSoup
from urllib.request import urlopen

url = 'http://www.gatherproxy.com/ru/sockslist'
soup = BeautifulSoup(urlopen(url).read(), 'html.parser')
scripts = soup.find_all('script')
print(scripts)

Результат:

[<script src="/Content/js/jquery.min.js" type="text/javascript"></script>, <script src="/content/js/jquery.marquee.zipped.js?v=1" type="text/javascript"></script>, <script src="/content/js/gp.zipped.js?v=118" type="text/javascript"></script>, <script src="/content/js/scripts.js?v=16" type="text/javascript"></script>, <script>                            document.write('186.225.149.170')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('103.21.163.70')</script>, <script>                            document.write('6667')</script>, <script>                            document.write('119.252.170.42')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('123.205.183.100')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('103.21.163.81')</script>, <script>                            document.write('6667')</script>, <script>                            document.write('138.197.157.32')</script>, <script>                            document.write('1080')</script>, <script>                            document.write('184.176.166.8')</script>, <script>                            document.write('1080')</script>, <script>                            document.write('12.1.69.228')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('184.178.172.18')</script>, <script>                            document.write('15280')</script>, <script>                            document.write('118.163.161.97')</script>, <script>                            document.write('1616')</script>, <script>                            document.write('103.21.161.105')</script>, <script>                            document.write('6667')</script>, <script>                            document.write('183.78.149.52')</script>, <script>                            document.write('1080')</script>, <script>                            document.write('118.139.176.242')</script>, <script>                            document.write('1197')</script>, <script>                            document.write('114.69.238.10')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('112.133.225.56')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('114.33.10.164')</script>, <script>                            document.write('30022')</script>, <script>                            document.write('109.72.103.146')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('103.21.163.76')</script>, <script>                            document.write('6667')</script>, <script>                            document.write('109.224.16.34')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('181.112.39.74')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('103.253.181.130')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('107.181.174.63')</script>, <script>                            document.write('4002')</script>, <script>                            document.write('109.104.79.203')</script>, <script>                            document.write('14541')</script>, <script>                            document.write('177.94.246.248')</script>, <script>                            document.write('9999')</script>, <script>                            document.write('107.170.7.132')</script>, <script>                            document.write('12517')</script>, <script type="text/javascript">(function (i, s, o, g, r, a, m) {i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {(i[r].q = i[r].q || []).push(arguments)}, i[r].l = 1 * new Date(); a = s.createElement(o),m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');ga('create', 'UA-40469601-1', 'gatherproxy.com');ga('send', 'pageview');</script>, <script type="text/javascript">
    (function () {
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = 'https://apis.google.com/js/plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    })();
</script>]

Все прекрасно работает, не знаю что у Вас вызвало такую проблему. Сравните мой и Ваш код, может найдете в чем делали ошибку.

1
  • 1
    read() можно не указывать -- для объектов-io BeautifulSoup сам вызовет его: soup = BeautifulSoup(urlopen(url), 'html.parser')
    – gil9red
    Commented 11 окт. 2018 в 12:26

Ваш ответ

Нажимая «Отправить ответ», вы соглашаетесь с условиями пользования и подтверждаете, что прочитали политику конфиденциальности.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.