Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k points)
closed by

I'm actually new to python and python-requests.

Look at the below code:

import requests

from pattern import web

import re

import pandas as pd

def list_of_prices(url):

    html = requests.get(url).text

    dom = web.DOM(html)

    list = []

    for person in dom('.freelancer-list-item .medium.price-tag'):

        currency = person('sup')

        amount = person('span')

        list.append([currency[0].content if currency else 'na', 

                     amount[0].content if amount else 'na'])

    return list

list_of_prices('http://www.peopleperhour.com/freelance/data+analyst#page=2')

At the point when I run this code, I get a blunder like a module design not found, however that is not what I'm requesting assistance with. 

Where does .content come from? Is it utilized distinctly with Python requests?

closed

4 Answers

0 votes
by (19k points)
 
Best answer
The .content attribute in the provided code snippet does not originate from Python requests. Instead, it belongs to the pattern library's pattern.web.Element class, which is utilized in the code.

In the context of the pattern.web.Element class, the .content attribute serves the purpose of retrieving the inner HTML content of an HTML element. It allows you to extract the actual content enclosed within the HTML tags.

In the given code, currency[0].content and amount[0].content are used to retrieve the inner HTML content of the currency and amount elements, respectively. These elements are obtained using the person('sup') and person('span') calls, which find the first occurrences of the sup and span elements within the person element.

It is important to note that the usage of .content is specific to the pattern library and not exclusive to Python requests. It provides functionality for parsing HTML and extracting relevant information from HTML elements.

If you encounter a "module design not found" error, ensure that the required module, pattern, is installed in your Python environment by executing the command pip install pattern.
0 votes
by (26.4k points)

You can install the module pattern:

pip install pattern

requests have a substance property thus patterns. On the off chance that you don't have pip introduced, download the compress/zip here, run the setup.py record in the registry with python setup.py introduce.

Are you looking for a good python tutorial? Join the python course fast and gain more knowledge in python.

0 votes
by (25.7k points)
The .content attribute you see in the code snippet is not specific to Python requests. It is actually part of the pattern.web.Element class from the pattern library that is being used in your code.

The pattern.web.Element class represents an HTML element and provides various methods and attributes to extract information from the element. The .content attribute specifically retrieves the inner HTML content of the element.

In your code, currency[0].content and amount[0].content are used to extract the inner HTML content of the currency and amount elements, respectively. These elements are obtained using the person('sup') and person('span') calls, which find the first sup and span elements within the person element.

So, .content is not related to Python requests itself but rather a feature provided by the pattern library for parsing HTML and extracting information from HTML elements.

If you encounter a "module design not found" error, make sure that the required module, pattern, is installed in your Python environment. You can install it using the command pip install pattern.
0 votes
by (15.4k points)
The attribute .content you see in the provided code snippet does not pertain specifically to Python requests. It is, in fact, a feature of the pattern library's pattern.web.Element class, which is utilized in the code.

Within the context of the pattern.web.Element class, .content is employed to retrieve the inner HTML content of an HTML element. This attribute allows you to extract the actual content encapsulated within the HTML tags.

In the given code, currency[0].content and amount[0].content are used to obtain the inner HTML content of the currency and amount elements, respectively. These elements are accessed using the person('sup') and person('span') methods, which locate the first occurrence of the sup and span elements within the person element.

Therefore, it is important to note that .content is not directly related to Python requests itself, but rather a feature provided by the pattern library for parsing HTML and extracting relevant information from HTML elements.

In case you encounter a "module design not found" error, kindly ensure that the required module, pattern, is installed within your Python environment. You can install it by executing the command pip install pattern.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...