selenium – how to write a scraped data into dictionary using python?

I want to write my scraped data into a dictionary using python. the format for the output is :

{‘title’ :{‘author_name’:{‘price’:150}},….}

can anyone give me an idea to do with python?

this is an urgent requirement for me, so can anyone give me an idea to do with python?

thanks in advance.


def books():
   country = str(input('Enter the country:')
   driver = open_driver_connection()
   title = ('In Search of Lost Time','Ulysses','Don Quixote','The Great Gatsby','War and Peace')
   for lists in title:
            driver.find_element(By.XPATH, " search box").send_keys(lists)
            driver.find_element(By.XPATH, "xpath of the country in search box").send_keys(country)
            driver.find_element(By.XPATH, " for submit").click()
            elems = driver.find_elements_by_xpath("list of websites for the best search")
            hrefs =()
            for href in hrefs:
                        price = driver.find_element_by_xpath("").text


                        price = driver.find_element_by_xpath("other path for few links").text


                    price = ("Price not mentioned")
                author_name = driver.find_element(By.XPATH, " ").text

A library required which generates dictionary attack passwords (for testing my theory)

I have calculated that 15 characters long password will take more than 8000 years to crack by the most powerful supercomputer available today.

My theory is that – Even if passwords are simple and easy to remember but if they are atleast 15 characters long, then these passwords are unbreakable.

So, according to me a simple but long password like – “iloveunitedstates” is an unbreakable password.

But someone pointed out that using dictionary attack, this password can be hacked easily.

But I am not convinced that this password can be broken.

So, I wanted to test it myself. So, is there a library or tool that generates dictionary attack passwords, so that I can use it to see if the password “iloveunitedstates” is crackable or not.

Please let me know if there is such a library or tool.

How do I read a character from a string and have it read a correlating Dictionary entry – python

I’m trying to write a code to take the first letter of the string, and if valid, output where in the dictionary it comes from. For the second character in a string (a number) it should tell me whether it’s rural (a 0) or urban (any other number). For whatever reason it seems to think everything is rural, and outputs all of the dictionary. Please help?

import sys
# Input
print("From the given Canadian Postal Code, this program will tell the user n" +
      "where in Canada the Postal Code is from, and whether or not the code n" +
      "is from a rural or urban address. nPress 'Enter' to quit.n")
postalCode = input("The Postal code must be six characters long in the n" +
                   "format A#A #A#. Please enter the Postal Code: ")

# Process
postalCode = postalCode.replace(" ", "")
postalCode = postalCode.upper()

letters = ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V" "W", "X", "Y", "Z")
numbers = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
letterInvalid = ("D", "F", "I", "O", "Q", "U", "W", "Z")
letterValid = {"A": "Newfoundland", "B": "Nova Scotia", 
               "C": "Prince Edward Island", "E": "New Brunswick", 
               "G": "Quebec", "H": "Quebec", "J": "Quebec", 
               "K": "Ontario", "L": "Ontario", "M": "Ontario", 
               "N": "Ontario", "P": "Ontario", "R": "Manitoba", 
               "S": "Saskatchewan", "T": "Alberta", "V": "British Colombia", 
               "X": "Nunavut or the Northwest Territories", "Z": "Yukon"}
isUrban = True
valid = True

if postalCode == "":
    print("n   Exiting program.")

for i in range(0, len(postalCode), 2):
    if postalCode(i) not in letters or postalCode(i+1) not in numbers:
        valid = False
        for i in range(0, 2, 1):
            if postalCode(i) in letterInvalid:
                valid = False
        for i in range(0, 3, 1):
            if postalCode(i+1) == "0":
                isUrban = False

# Output
    print(postalCode, "is a valid Postal Code")
    for letter, province in letterValid.items():
        print("The code is from", province.title() +".")
        print("The code is from an urban area.")
        print("The code is from a rural area.")
    print(postalCode, "is not a valid Postal Code")

dictionary – Add a custom word to Google Japanese keyboard

Gboard (Google Keyboard) has a very simple way to add new words to it.

Open the Gboard app, go to ‘dictionary’ > ‘personal dictionary’ > (Japanese) > plus (+) symbol on the top right. Now, type the desired word, and add a shortcut, that way every time you type the shortcut, it will give you the option to switch to the desired word.

For example, if I want to type the word
Привет in Russian, but I don’t want to switch my keyboard from English to Russian just to type that word, so I made a shortcut that every time I write the letter P the word will show up in the suggestion bar. See screenshot below

c# – Inheriting from Dictionary class with tuple as value

I have a class that inherits from Dictionary<Tkey, TValue>.

I need my Value part of the KeyValue pair to be a a Tuple (int, bool )

public class IssueRowValidationDictionary :
        Dictionary<string, (int, bool)>
        public IssueRowValidationDictionary() : base() { }

        internal void Add(string issueReference, int rawRowNumber, bool v)
            Add(issueReference, (rawRowNumber, v));

In my code there are cases where I need to get the int Value part of the dictionary Element

             var intValue = issueRowValidationDictionary('keyRef').Item1;

Is there a more elegant way for Example to create a specific property that will only return the int part of the value. Any suggestions for improvement of my code are welcomed

algorithms – LZW with dictionary clearing

How does LZW decompress data with dictionary clearing/flushing? I understand that a space is reserved in the dictionary that represents a clear code (usually 256), but how is this code actually used when compressing and decompressing data? My thoughts for compression are that it checks the table size, and if the table size has reached the maximum size it appends the flush character to the output before resetting the dictionary. I’m not sure what it does for decompression though.

Python: How can loop over two lists one for key and one for value and place that into a new empty dictionary?

Here is the data I have I want to loop over the two lists the symbol list as the key and symbol_name as the value
how do I do it with using the loop

calculator_dict = {} # the new dictionary i want to put both the list into

symbols = (“+”, “-“, “*”, “/”)

symbol_name = (“add”, “subtract”, “multiply”, “divide”)

for symbol in symbols:

for name in symbol_name:

calculator_dict(symbol) = name


What i want to be printed is:

calculator_dict = {
“+”: “add”,
“-“: “subtract”,
“*”: “multiply”,
“/”: “divide”,

algorithm – Assessing BigO/small o for forming a dynamic dictionary based on searched key and values pair

I am trying to create a dictionary with a file containing text based on a matched pattern. Lines containing key_str should become keys and subsequent lines not matching key_str should become values and get associated with keys in the dictionary. so i have below code working: But I need help and getting the Big O analysis. How could i say my logic is worth case, Best Case or good case? Also, which case is small o and which is big O

File: file2dict.result-soa1




my_dict: {ml1: ('/var','/home'), cpuml2: ('/var','/home')}


import os
homedir = os.environ.get('HOME')

key_str = "ml"
my_dict = {}
val_list = ()
key = ''
with open(homedir + '/backup/file2dict.result-soa1') as file2dict:
    for line in file2dict:
        words = line.split()
        for aWord in words:
            if key_str in aWord:
                if key:
                    my_dict(key) = val_list
                    val_list = ()
                    key = aWord
                    key = aWord
    my_dict(key) = val_list

java – Replace words from a file with words from a dictionary based file

I don’t think you need to test everything around opening the input file, closing it, handling exceptions, etc. For the purpose of this task, I believe you want to test your logic, and trust that FileReader or FileInputStream etc just work.

I would have a class that that can read the format of the dictionary (not provided, presumably this is FileBasedDictionary), and create a test of that class that it produces the expected Map<String, String>.

Then have a class that does business logic (i.e. the word replacement) that can operate independant of the source of the data (by taking in a flexible type like a BufferedReader). You can add a test case that demonstrates how to create a valid data source, while also demonstrating the business logic – tests are as much about documentation/demonstration as they are about checking.

import java.util.Map;

public class DictionaryReplacementService {
    private Map<String, String> dictionary;
    public DictionaryReplacementService(Map<String, String> dictionary) {
        this.dictionary = dictionary;

    public void replaceWords(BufferedReader input, BufferedWriter output)
            throws IOException {
        String line;
        while ((line = input.readLine()) != null) {
            for (Map.Entry<String, String> entry : dictionary.entrySet()) {
                line = line.replaceAll(entry.getKey(), entry.getValue());
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.LinkedHashMap;
import java.util.Map;

import org.junit.jupiter.api.Test;

class DictionaryReplacementServiceTest {

    void test() throws IOException {
        String source = "It was the best of times, it was the blurst of times.";

        Map<String, String> dictionary = new LinkedHashMap<String, String>();
        dictionary.put("blurst", "worst");

        StringWriter outString = new StringWriter();
        try (BufferedReader in = new BufferedReader(new StringReader(source));
                BufferedWriter out = new BufferedWriter(outString)) {
            new DictionaryReplacementService(dictionary).replaceWords(in, out);

        assertEquals("It was the best of times, it was the worst of times.",


In this case, the user of your class would just need to replace StringReader with FileReader if that’s what they wanted – the DictionaryReplacementService is not interested in that.

A last note is about exceptions and return values. Instead of returning true for success and false for failure, I prefer to return void for success and just throw any exceptions that mean the success case is not possible (in my case, the try is just to ensure the resources are closed – it doesn’t catch any exceptions, and throwing an exception from a JUnit test means a test failure, which is what we want).

You said you don’t want to trivialize file i/o and you want to test what happens when problems happen, but that’s not a concern of DictionaryReplacementService – it only needs to signal that something went wrong. In a full program, you would have logic in the UI layer to try and recover (let the user know there was a problem, prompt them to try again or use a different file etc). You’re not writing that UI layer now, so I wouldn’t expect to see tests about it now.

Regarding Dictionary Attack – Information Security Stack Exchange

A dictionary attack is usually carried out offline, not against an online website, for exactly the reason you raise. It requires that the password database be compromised and available for offline attacks.

A password spray attack is more common for online resources. With a password spray, a small number of passwords are tested against a large number of accounts, spreading out the attempts to avoid triggering locked accounts. This is based on the fact that most accounts lock on X amount of failures within a certain time frame.

Even with a gentle password spray, locking out accounts is a real danger. Online password attacks are hard!