Fetch Data by Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Fetch Data by Python

How to fetch one data field from a webpage into a text file or variable using python? for e.g. I want the text "username" from Facebook login page into a text file or variable.

11th Jan 2018, 11:19 AM
DAKSHESH SHARMA
DAKSHESH SHARMA - avatar
1 Answer
0
What you are trying to make is called a "web crawler". There are libraries to help you with this. I would suggest watching these tutorials which will explain how to make one: Part 1: https://youtu.be/XjNm9bazxn8 Part 2: https://youtu.be/sVNJOiTBi_8 Part 3: https://youtu.be/pLHejmLB16o For the text file part use built in file editing e.g # opens/creates file "example.txt" then writes everything in the web_info # variable into it with open("example.txt", "w") as f: f.write(web_info) OR try: f = open("example.txt", "w") f.write(web_info) finally: f.close() ***Warning: as stated in the first part, web crawling on some websites is against their policies*** I hope that helps
12th Jan 2018, 9:46 PM
TurtleShell
TurtleShell - avatar