vendredi 16 août 2019

How to select a random URL form extracted URL list

I am trying to extract the proxy urls and would like to use one random url

import requests
from lxml import html
import random

def get_proxy():
    url = 'https://sslproxies.org/'
    req = requests.get(url)
    iptree = html.fromstring(req.content)
    iprange = range(1,20)
    for ips in iprange:
        https = iptree.xpath('//*[@id="proxylisttable"]/tbody/tr[%d]/td[7]//text()'%ips)
        iptd = iptree.xpath('//*[@id="proxylisttable"]/tbody/tr[%d]/td[1]//text()'%ips)
        port = iptree.xpath('//*[@id="proxylisttable"]/tbody/tr[%d]/td[2]//text()'%ips)
        for htp in https:
            if htp=="yes":
                for (ips, por) in zip(iptd, port):
                    iplist = ("https://" + ips + ":" + por)
                    print(iplist)

get_proxy()

i want to assign one random URL to a string and use it in my web scraper, but i am unable to select random one




Aucun commentaire:

Enregistrer un commentaire