Fun with python requests module

I was reading this part of the pym book and thought that I should change this code a little bit so that it can do some better thing like instead of storing the content in a text file it stores it in a HTML file and it also checks if there is any same named file exists in the directory or not. Here is the code –

import os.path
import requests

def download(url):
    Download the given url and saves it to the current directory
    :arg url: URL of the file to be downloaded.
    req = requests.get(url)
    if req.status_code == 404:
        print('No such file found at %s' % url)
    fileName = url.split('/')[-1].split('.')[0] + '.html'
    if os.path.isfile(fileName):
        print('Same file name already exist')
        with open(fileName, 'wb') as fobj:
        print('Download over')

if __name__ == "__main__":
    url = input("Enter a URL: ")

Above we are getting the content of the content of the url by requests.get(url) method. Then checking if that url is valid or not. If valid then parsing the url by split() method like first we are splitting it by “/” and taking the last value of the list and then splitting it again with “.” and taking the first value of the list. Then checking if there is no same name file exist and if there is no same name file then we are creating a file then writing the content in the file.
Thank you 🙂

28 thoughts on “Fun with python requests module

  1. Woah! I’m really digging the template/theme of this blog.

    It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between user friendliness and visual appearance.
    I must say you’ve done a awesome job with this.

    In addition, the blog loads extremely quick for me on Firefox.
    Excellent Blog! I am not sure where you’re getting your information, but good topic.
    I needs to spend some time learning more or understanding more.

    Thanks for excellent info I was looking for this information for
    my mission. I am sure this piece of writing has touched all
    the internet viewers, its really really pleasant post
    on building up new blog.


  2. พบมิติใหม่แห่งการแทงหวยได้ที่ Fun88 หวยบริการที่พัฒนาขึ้น เพื่อเอาใจนักเสี่ยงโชคโดยเฉพาะ เพราะนอกจากคุณจะสามารถแทงบอออนไลน์กับFun88
    กีฬาแล้ว เรายังมีระบบการใช้งานของคาสิโนที่เล่นง่ายจ่ายไวและจ่ายจริง
    สำหรับใครที่เป็นคอหวยที่นี้คือสวรรค์ของคุณ บนเว็บไซต์พนันออนไลน์ที่มีความปลอดภัยสูงนี้ ได้เปิดบริการ Fun88 เล่นหวย ซึ่งเป็นการแทงหวยในรูปอีกรูปแบบหนึ่งที่กำลังเป็นที่นิยมกันอย่างมากในปัจจุบัน สำหรับผู้ที่สนใจหรือชื่นชอบการแทงหวยออนไลน์คุณสามารถเข้ามาเป็นส่วนหนึ่งกับเว็บไซต์ Fun88
    ของเราได้ [ขั้นตอนสมัคร-fun88/]( “ขั้นตอนสมัคร-fun88/”)


  3. Registration Open an W88 account to have all of our online gambling gaming and promotions amusement of superior quality at very
    good value. We feel in pleasing our respected
    clientele with assorted form of downpayment bonuses and promotions.


    Turned out to be our other half and earn huge percentage quantities each month by driving a
    motor vehicle members to W88.

    W88 strives to supply a channel of home entertainment for our client in a confident way.

    Now we have set up leading safeguards to ensure and promote to
    blame gaming.


    A Solid and Protect Wagering Solution. The privacy of your own into is very important to
    us and we conform to tight privacy and confidentiality insurance

    Sporting activities Playing & Survive Gambling

    This site offers all the major sporting activities which
    includes British Highest regarded League, Spanish language La Liga, Italian Serie A, UEFA Champions League, French Ligue 1, German Bundesliga 1, NBA, NCAA and NFL Wives Basketball, Golf, System
    1 and a lot more. We offer nearly 4,000 Stay Gambling soccer fits each month in your betting pleasures.

    Web-based On line casino

    Execute online casino gaming applications on the internet.

    Decide on Roulette, Blackjack, Online video Poker, others,
    Progressives and Slots in addition get your an opportunity
    to win considerably more Internet casino Jackpots on W88.

    Are living Online casino

    Now we have substantial assortment of deals.

    Included in this are Live life Dealer On line casino with Stay Reception point of view, gorgeous Oriental traders, Dwell Baccarat, Live Sic Bo, Reside Dragon Tiger
    and Live Roulette, Over the internet Online casino
    Slots and simple to experience Keno video game titles.

    Special deals Deposit Bonus and Welcome Benefit make available for any new participants.
    Reload Cash and Bonus Discounts for current buyers

    Enable Heart

    Go and visit our Frequently asked questions page for sporting betting and video
    gaming assistance. Its content has help out on bill deposit, withdrawal, technical and opening benefit.

    Cost Approaches

    We provide you with fantastic choice for customers to deposit and take away as soon as you succeed throughMoneybookers and
    NETELLER, World wide Standard bank Exchange, North western Union and numerous others.
    We have a good deal, good games start with W88.

    Give Us A Call

    We are available 24/7 via Live Chat, E and Telephone-mail, if
    you need any help or have any questions about Live betting or our casino games.

    My page :: [ass]( “ass”)


  4. Enrollment Opened an W88 accounts to enjoy all our via the internet wagering gaming
    and promotions pleasure of superior quality
    at extremely excellent value. We think in rewarding our highly valued shoppers with some other version of downpayment promotions
    and bonuses.


    End up being our partner and earn substantial profit
    quantities each month by cruising game enthusiasts to W88.

    W88 strives to provide a funnel of enjoyment to your clients in a very
    positive way. We certainly have on hand key safety measures to
    ensure and promote liable casino.


    A Sound and Safeguarded Playing Procedure. The security within your into is necessary to we and us comply with tight privacy and confidentiality rules.

    Sports Wagering And Stay Playing

    This site offers all of the professional sports such as English
    The best League, Spanish language Los angeles
    Liga, Italian Serie A, UEFA Champions League, French Ligue 1, German Bundesliga
    1, NCAA, NBA and NFL Females Basketball, Football, Strategy 1 and much more.
    Our company offers nearly 4,000 Exist Playing soccer complements 30 days
    with regards to your wagering pleasures.

    Over the internet Casino

    Have fun with playing casino site gaming applications on the
    internet. Pick Roulette, Blackjack, Footage Poker, Slots, others
    and Progressives as well as get those possiblity to gain considerably more
    Casino Jackpots on W88.

    Reside Gambling house

    We certainly have considerable variety gives.
    Examples of these are Are located Seller Gambling house
    with Live life Reception look at, lovely Asian sellers, Are located Baccarat,
    Live Sic Bo, Exist Dragon Live and Tiger Roulette, On line Casino Slot machines uncomplicated to learn Keno video game titles.

    Special offers Down payment Bonus and Welcome Reward offer for all those
    new participants. Reload Bonus and Cash Rebates for existing
    shoppers simultaneously

    Help Heart

    Consider our Frequently asked questions web site for athletic gambling and video gaming help out.
    It includes help out on bank account deposit, opening, withdrawal and
    technical support.

    Transaction Techniques

    This site offers terrific option for potential customers
    to put in and withdraw when you earn by means ofMoneybookers and NETELLER, World-wide Financial institution Move, American Union and others.
    We certainly have it, good games focus on W88.

    Call Us

    If you need any help or have any questions about Live betting or our
    casino games, we are available 24/7 via Live Chat, Telephone and E-mail.

    my homepage [lesbian]( “lesbian”)


  5. Pingback: URL
  6. I have been surfing online greater than 3 hours these days, yyet
    I by no means found any ineresting article likme yours.

    It is pretty value sufficient for me. In mmy opinion, if
    all webmasters andd bloggers made excellent content as you
    did, the net will probably be a lot more helpful than ever before.

    my homepage fiber optjc cable manufacturer ([]( “”))


  7. However the explosion of curiosity in seasonal and pesticide-free food tilled in local soil
    is now spilling over into the commercial flower trade, making it potential to go native, even in the
    course of winter.


  8. Simply wish tօ ѕay yoᥙr article iѕ as amazing.
    Thee clearneess іn your pst iѕ simmply spectacular and і can assume yoս aare ann expert оn tthis subject.
    Welll wіth ylur permission аllow me to grab youг RSS feed tߋ keeⲣ updated with forthcoming post.

    Thanks a mіllion and ρlease carry on tһe gratifying worқ.

    mʏ webpage … [Weight loss Pills]( “Weight loss Pills”)


  9. What’s Happening i am new to this, I stumbled upon this I’ve found It
    absolutely helpful and it has aided me out loads.
    I’m hoping to give a contribution & aid different users like its helped
    me. Great job.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s