Sponsored Content
Top Forums Programming Python Web Page Scraping Urls Creating A Dictionary Post 302998746 by metallica1973 on Wednesday 7th of June 2017 02:54:48 PM
Old 06-07-2017
I cross referenced the html file with the output urls and its correct. Most of the html files do contain multiple duplicate urls as in:

http://www.blah.org
http://www.blah.org
http://www.blah.org

So I would need to remove the duplicates. I have dont this before in the past using:
Code:
tut_links=list(set(tut_links))

Let me give this a shot and see what happens. Thanks for all the help. I will let you know how it goes.

---------- Post updated 06-07-17 at 02:54 PM ---------- Previous update was 06-06-17 at 04:03 PM ----------

Thanks for all the help. Here is the finish code:
Code:
tut_links = {}

for subdir, dirs, files in os.walk('./html/tutorials/blah'):
    for tut in files:
        if tut.endswith(".html"):
	    tut_links[tut] = []
            fpath = os.path.join("./html/tutorials/blah", tut)
            content = open(fpath, "r").read()
            file = BeautifulSoup(content, 'lxml')
            for links in file.find_all('a', href=True):
		urls = links.get('href')
	    	if urls.startswith('http' or 'https'):		
	           tut_links[tut].append(urls)
	    for dup in tut_links.values(): --> removes duplicate urls from the dictionary value list
    		dup[:] = list(set(dup))

Worked like a champ
Code:
'bigbadwolf.htlm' : ['https://www.blah.com', 'http://www.blahblah.com','http://www.blahblahblah.com']


Last edited by metallica1973; 06-07-2017 at 04:37 PM..
This User Gave Thanks to metallica1973 For This Post:
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

making a web page

Hey im new to unix! I am tryin to create a web page in unix and have done it all but when i try and load it it says permission denied!?> i have chmod a+rx for folder and file to make sure but still permissions wont let me?! any ideas can anyone do a quick run through of how to make a web page... (4 Replies)
Discussion started by: shashora
4 Replies

2. UNIX for Dummies Questions & Answers

Accessing Web Page

Hello, I am new to unix, but wanted to know how can we fetch data from a web page (i.e. an HTML Page), my requirement is to read an html page and wanted to create a flat file (text file) based on the contents available in the mentioned HTML page. Thanks Imtiaz (3 Replies)
Discussion started by: Imtiaz
3 Replies

3. UNIX for Dummies Questions & Answers

how do i make a web page

hey uhh this is my first post and i was wondering how do i make a web page for like a small business or something anything will help thanks (3 Replies)
Discussion started by: Neil Peart
3 Replies

4. UNIX for Dummies Questions & Answers

Make a Web page

I'm 13 years of age and I am into computers. I am trying to learn how to make a webpage. I could use the help and I would greatly appriciate it. (1 Reply)
Discussion started by: lydia98
1 Replies

5. Programming

fetching a web page in C

Hello, I'm a total newbie to HTTP commands, so I'm not sure how to do this. What I'd like is to write a C program to fetch the contents of a html page of a given address. Could someone help with this? Thanks in advance! (4 Replies)
Discussion started by: rayne
4 Replies

6. Shell Programming and Scripting

Creating a dictionary with domain name adjuncted

Hello, I have created a dictionary which has the following structure: DOMAINWORD=(equivalent in English)gloss(es) in Hindi each separated by a comma(equivalent in English)gloss(es) in Hindi each separated by a comma or a semi-colon An example will make this clear ... (13 Replies)
Discussion started by: gimley
13 Replies

7. Shell Programming and Scripting

Counting all words that start with a capital letter in a string using python dictionary

Hi, I have written the following python snippet to store the capital letter starting words into a dictionary as key and no of its appearances as a value in this dictionary against the key. #!/usr/bin/env python import sys import re hash = {} # initialize an empty dictinonary for line in... (1 Reply)
Discussion started by: royalibrahim
1 Replies

8. Shell Programming and Scripting

Creating verbal structures from a dictionary and a template

My main aim here is to create a database of verbs in a language to Hindi. The output if it works well will be put up on a University site for researchers to use for Machine Translation. This because one of the main weaknesses of MT is in the area of verbs. Sorry for the long post but the problem... (4 Replies)
Discussion started by: gimley
4 Replies
Color::Library::Dictionary(3pm) 			User Contributed Perl Documentation			   Color::Library::Dictionary(3pm)

NAME
Color::Library::Dictionary - Color dictionary for Color::Library METHODS
@colors = $dictionary->colors Returns the list of Color::Library::Color objects contained by $dictionary Will return a list in list context, and a list reference in scalar context @names = $dictionary->names @names = $dictionary->color_names Returns the list of color names contained by $dictionary Will return a list in list context, and a list reference in scalar context $color = $dictionary->color( <query> ) Returns a Color::Library::Color object of $dictionary found via <query> A query can be any of the following: color name A color name is like "blue" or "bleached-almond" color title A color title is like "Dark Green-Teal" color id A color id is in the form of <dictionary_id>:<color_name>, for example: "x11:azure1" $id = $dictionary->id $name = $dictionary->name Returns the id (name) of $dictionary, e.g. svg x11 vaccc nbs-iscc-f $title = $dictionary->title Returns the title of $dictionary, e.g. SVG X11 VACCC NBS/ISCC F $subtitle = $dictionary->subtitle Returns the subtitle of $dictionary, if any $description = $dictionary->description Returns the description of $dictionary, if any perl v5.14.2 2011-12-07 Color::Library::Dictionary(3pm)
All times are GMT -4. The time now is 02:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy