Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
web scraping HTML - :(
#11
And also move with open into the loop.
import requests

domains = ['https://webdesigner.dk', 'https://www.dk4.dk/item/4128-persondatapolitik']
for domain in domains:
    print(domain)
    response = requests.get(domain)
    print(f"Response data length: {len(response.text)}")
    # Remove # from line below to see source
    # print(response.text)

    with open('source.html', 'a', encoding='utf-8') as f:
        f.write(response.text.strip())
Reply
#12
Thank you for keep trying to help me out here, but it is not working.

I have posted a picture of my screen.

https://imgur.com/hg0P9fq

The 10696 lines is still only from the last mentioned website.
Reply
#13
Your writing isn't in the loop, is it?
Reply
#14
(Apr-05-2021, 03:37 AM)ndc85430 Wrote: Your writing isn't in the loop, is it?

I'm sorry but I don't know what you mean by this.


Please see the link with the image I posted in my previous post
Reply
#15
Here's a link to some scraping software I did a couple weeks ago:
https://python-forum.io/newreply.php?tid...yto=139401
Reply
#16
The call to write is done once, after the loop. Is that really what you intended?
Reply
#17
Thus is the First thing I try to setup as code, so I dont know

The intention is:

Put in my list of addresses, have it combine all the public HTML source code into one long text That I can view.

- thats it, it is just instead of me going through each website, right click and view source
Reply
#18
I don’t have any idea How to get it to loop, it was an idea for me to try this out, but yeah, doesn’t seem to work out
Reply
#19
Do you understand that indentation tells you what's part of a block, like a for loop?
Reply
#20
No.

I just wanted to try this out instead of manually doing 100 websites, but It doesn’t
Seem so simple to do, after all :)

T
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Web Scraping can not getting all HTML content yqqwe123 0 1,645 Aug-02-2021, 08:56 AM
Last Post: yqqwe123
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,647 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 2,370 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020