Here we go, I using a text file with url in it, one per line. I am using a for loop to go one line at a time through the list. Then I am feeding that for loop into an email scraping
code. I get about the first url then an error.
Here is my code
['[email protected]', '[email protected]', '[email protected]']
Traceback (most recent call last):
File "D:\Users\computer\Desktop\python use file\read_fil_and_use_for_loop.py", line 7, in <module>
text = urllib.request.urlopen(line).read().decode('utf-8')
File "D:\Python37\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "D:\Python37\lib\urllib\request.py", line 510, in open
req = Request(fullurl, data)
File "D:\Python37\lib\urllib\request.py", line 328, in __init__
self.full_url = url
File "D:\Python37\lib\urllib\request.py", line 354, in full_url
self._parse()
File "D:\Python37\lib\urllib\request.py", line 383, in _parse
raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: ''
I have just got in to using for loop, so I am not very good at them yet.
Hope some one can help.
renny
ps. the list
http://www.cityofalbionmi.gov/
http://www.revize.com
http://www.cityofalbionmi.gov/government.../index.php
http://www.cityofalbionmi.gov/government.../index.php
http://www.cityofalbionmi.gov/residents/.../index.php
http://www.cityofalbionmi.gov/government.../index.php
http://www.cityofalbionmi.gov/department...ration.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department..._sewer.php
http://www.cityofalbionmi.gov/residents/index.php
http://albionmich.com/calendar/index.html
code. I get about the first url then an error.
Here is my code
import urllib.request, re url_files = open("test.txt", "r") lines = url_files.readlines() for line in lines: text = urllib.request.urlopen(line).read().decode('utf-8') regex = re.compile(r'[\w.-]+@[\w.-]+') email = re.findall(regex, text) print(email) url_files.closeHere is the error, you can see the emails from the first url, then the error
['[email protected]', '[email protected]', '[email protected]']
Traceback (most recent call last):
File "D:\Users\computer\Desktop\python use file\read_fil_and_use_for_loop.py", line 7, in <module>
text = urllib.request.urlopen(line).read().decode('utf-8')
File "D:\Python37\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "D:\Python37\lib\urllib\request.py", line 510, in open
req = Request(fullurl, data)
File "D:\Python37\lib\urllib\request.py", line 328, in __init__
self.full_url = url
File "D:\Python37\lib\urllib\request.py", line 354, in full_url
self._parse()
File "D:\Python37\lib\urllib\request.py", line 383, in _parse
raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: ''
I have just got in to using for loop, so I am not very good at them yet.
Hope some one can help.
renny
ps. the list
http://www.cityofalbionmi.gov/
http://www.revize.com
http://www.cityofalbionmi.gov/government.../index.php
http://www.cityofalbionmi.gov/government.../index.php
http://www.cityofalbionmi.gov/residents/.../index.php
http://www.cityofalbionmi.gov/government.../index.php
http://www.cityofalbionmi.gov/department...ration.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department.../index.php
http://www.cityofalbionmi.gov/department..._sewer.php
http://www.cityofalbionmi.gov/residents/index.php
http://albionmich.com/calendar/index.html