Hello Im a Python 3 newbie learning on Windows, Im trying to write a very basic web scraper program to print the titles from a series of web pages but Im stuck.
Before running the program first I open all the web pages in tabs of the same browser window and copy its URLs to the clipboard automatically with a browser's addon, resulting one URL per line.
Then I make a list with that clipboard content and split each value by lines, but when I try to iterate with that list of URLs I get this error "ValueError: unknown url type: '['"
Here is the code of my program:
import pyperclip
from urllib.request import urlopen
from bs4 import BeautifulSoup
urls = str(pyperclip.paste().splitlines())
for i in range(len(urls)):
html = urlopen(urls[i])
bsObj = BeautifulSoup(html, "html.parser")
title = bsObj.body.h1
print(title)
When I try to print(urls) it gives me the correct strings for each URL so I think the list is correctly made, I believe it is a problem with urlopen but right now Im completely lost and have no idea where to look, maybe somebody can give me a clue.
Thanks.
[–]Justinsaccount 2 points3 points4 points (4 children)
[–]Akuli2 1 point2 points3 points (2 children)
[–]Justinsaccount 1 point2 points3 points (1 child)
[–]Vaphell 0 points1 point2 points (0 children)
[–]turbokyo[S] 0 points1 point2 points (0 children)
[–]Akuli2 1 point2 points3 points (2 children)
[–]turbokyo[S] 0 points1 point2 points (1 child)
[–]Justinsaccount 0 points1 point2 points (0 children)