Jun 25, 2020 05:42 AM
(This post was last modified: Jun 25, 2020 05:44 AM by 0u1law.)
hey guys.
i need some help in the following case:
i want to write a program that uses my browser. i have a list of links i want to visit and download the source code automatically. thats it.
which packages do i need for this ?
if someone have a piece of code i would be glad!
PSEUDO-CODE:
list_of_links = [... ... ... ...]
for each in list_of_links:
-----open browser
-----show sourcecode
-----download sourcecode
-----close browser
and if there are another ways to do this in a more efficient way please let me know
and just for the curiosity is there a method to do this with bash scripting?
best regards
0u1law
To automate it better you can use Selenium, just initialize a driver, save the sourcecode on a string and save it on a file and done.
(Jun 25, 2020 05:42 AM)0u1law Wrote: hey guys.
i need some help in the following case:
i want to write a program that uses my browser. i have a list of links i want to visit and download the source code automatically. thats it.
which packages do i need for this ?
if someone have a piece of code i would be glad!
PSEUDO-CODE:
list_of_links = [... ... ... ...]
for each in list_of_links:
-----open browser
-----show sourcecode
-----download sourcecode
-----close browser
and if there are another ways to do this in a more efficient way please let me know
and just for the curiosity is there a method to do this with bash scripting?
best regards
0u1law
Hi 🙃
Yes You can use Selenium, or Requests w/ BeautifulSoup.
Hit me up with a DM and i'll see what i can do for you. I'll show you how to do it also so you know and can show someone else one day!
Harley
"Give a Man a Fish, and You Feed Him for a Day. Teach a Man To Fish, and You Feed Him for a Lifetime"
(Jun 25, 2020 05:52 AM)Sickness Wrote: To automate it better you can use Selenium, just initialize a driver, save the sourcecode on a string and save it on a file and done.
Selenium is extremely inefficient.
Selenium was made for automated quality assurance, not for datascraping. Since OP just wants the actual source code, he can just use the Python.requests module to download that code.
This should work:
Code import requests
list_of_links = ["https://hackforums.net/", "https://google.com/", "https://wikipedia.org/"]
for link in links:
result = requests.get(link)
print("downloading link...")
#do whatever you want with the content
with f as open(link + "_download.txt", "w+")
f.write(result)
(Jun 25, 2020 11:31 AM)4Txe4y33C9zvNhMj Wrote: Selenium is extremely inefficient.
Selenium was made for automated quality assurance, not for datascraping. Since OP just wants the actual source code, he can just use the Python.requests module to download that code.
This should work:
Code import requests
list_of_links = ["https://hackforums.net/", "https://google.com/", "https://wikipedia.org/"]
for link in links:
result = requests.get(link)
print("downloading link...")
#do whatever you want with the content
with f as open(link + "_download.txt", "w+")
f.write(result)
i agree, requests would be perfect, bypassing the web browser and use less resource.
(Jun 25, 2020 11:31 AM)4Txe4y33C9zvNhMj Wrote: Selenium is extremely inefficient.
Selenium was made for automated quality assurance, not for datascraping. Since OP just wants the actual source code, he can just use the Python.requests module to download that code.
This should work:
Code import requests
list_of_links = ["https://hackforums.net/", "https://google.com/", "https://wikipedia.org/"]
for link in links:
result = requests.get(link)
print("downloading link...")
#do whatever you want with the content
with f as open(link + "_download.txt", "w+")
f.write(result)
You are right, but for pages that got protection for bots requests wont work always.
(Jun 25, 2020 11:44 AM)Sickness Wrote: You are right, but for pages that got protection for bots requests wont work always.
In the end you can always fake the actual HTTP request your browser sends. Even if they dynamically get content from an API endpoint you can scrape that too.
Jun 25, 2020 11:43 PM
(This post was last modified: Jun 25, 2020 11:48 PM by Pawnhub.)
(Jun 25, 2020 11:44 AM)Sickness Wrote: You are right, but for pages that got protection for bots requests wont work always.
Selenium wouldn't do any better in this case. I get more sites blocking selenium when cracking then request's.
But if you could 100% be able to mimic a proper request (which can be outstandingly hard with hidden variables and cookies etc) request's would still be the most viable.
Although, selenium can read JS unlike request's. So if the form he wants to scrape from loads from a Iframe then yes selenium is most viable since request's can't.
DO NOT DEAL WITH THIS MEMBER
Requests or Scrapy can do your Job.
I suggest selenium because It handles Javascript easily, and you can use headless chrome/firefox driver for speed,
(Jul 4, 2020 04:48 PM)SIM-4771460 Wrote: Requests or Scrapy can do your Job.
I suggest selenium because It handles Javascript easily, and you can use headless chrome/firefox driver for speed,
how can i use it headless?
DO NOT DEAL WITH THIS MEMBER
(Jul 9, 2020 12:46 PM)0u1law Wrote: how can i use it headless?
you can use headless chrome/firefox, just put --headless argument in code, or some headless browser.
(Jul 9, 2020 12:47 PM)SIM-4771460 Wrote: you can use headless chrome/firefox, just put --headless argument in code, or some headless browser.
thanks a lot!
|