-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Elias2660/formatting-changes
Automated formatting changes
- Loading branch information
Showing
4 changed files
with
53 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
import asyncio | ||
from playwright.async_api import async_playwright | ||
|
||
|
||
async def scrape_p_text(url): | ||
async with async_playwright() as p: | ||
browser = await p.chromium.launch() | ||
page = await browser.new_page() | ||
await page.goto(url) | ||
|
||
# Get all text from <p> tags | ||
p_tags = await page.query_selector_all('p') | ||
p_tags = await page.query_selector_all("p") | ||
p_texts = [await p.text_content() for p in p_tags] | ||
|
||
await browser.close() | ||
|
||
return p_texts | ||
|
||
|
||
async def main(): | ||
url = 'https://www.bbc.com/news/articles/cq5xjzqree2o' # Replace with the URL you want to scrape | ||
url = "https://www.bbc.com/news/articles/cq5xjzqree2o" # Replace with the URL you want to scrape | ||
p_texts = await scrape_p_text(url) | ||
print("Text in <p> tags:") | ||
text = " ".join(p_texts) | ||
text.replace(" ", " ") | ||
return text | ||
|
||
if __name__ == '__main__': | ||
|
||
if __name__ == "__main__": | ||
print(asyncio.run(main())) | ||
# scrape_p_text("https://www.bbc.com/news/articles/cq5xjzqree2o") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters