0

I've got a list if 10,000 URLs that I need to check and I'm automatizing the process of opening those URLs.

So far, I've done this and it works:

import webbrowser
import pandas as pd

urls  = pd.read_csv('urls.csv', delimiter='\'')

urls = urls['urls']

for url in urls[:100]:
    webbrowser.open_new(url)

Now, the problem is that with this I have to go to the code and change the slicing every time I need new URLs to be open. Do you think is possible to ask for an input to the users in order to select by themselves the range of slicing?

I've tried this:

for url in urls[{''}:{''}].format(input('Enter first line:  '), input('Enter last line:   ')):
    webbrowser.open_new(url)

And I get this error:

TypeError: cannot do slice indexing on <class 'pandas.core.indexes.range.RangeIndex'> with 
these indexers [{''}] of <class 'set'>

Thoughts?

pyseo
  • 431
  • 1
  • 6
  • 11

2 Answers2

0

Use

slice_idx = int(input('Enter index to slice at: '))

to get the index to slice at and then

urls.loc[:slice_idx, 'urls']

to get series of sliced urls.

Vishnudev Krishnadas
  • 10,679
  • 2
  • 23
  • 55
0

If limiting the amount of URLs to check and the library are not mandatory, you could try request library.

Something like:

import requests
import pandas as pd

urls  = pd.read_csv('urls.csv', delimiter='\'')

urls = urls['urls']

results = []

for url in urls:

    request = requests.get(url)

    if request.status_code == 200:
        results.append(url) 

Bare in mind that with this aproach, URLs should have http:// in the csv file. For example http://www.someweb.com